From 6c5ab65622683c15c9b9afb79d6af7e32303ddb9 Mon Sep 17 00:00:00 2001 From: Timothy Zakian Date: Fri, 19 Apr 2024 14:07:17 -0700 Subject: [PATCH] [3/n][enums] Move execution version updates --- .../bounds_tests.proptest-regressions | 8 +- .../src/unit_tests/bounds_tests.rs | 12 +- .../src/unit_tests/constants_tests.rs | 2 +- .../src/unit_tests/generic_ops_tests.rs | 39 +++-- .../src/unit_tests/large_type_test.rs | 5 + .../src/unit_tests/limit_tests.rs | 36 ++-- .../src/unit_tests/locals.rs | 3 + .../src/unit_tests/loop_summary_tests.rs | 158 ++++++++++------- .../src/unit_tests/many_back_edges.rs | 2 + .../src/unit_tests/mod.rs | 4 +- .../src/unit_tests/reference_safety_tests.rs | 11 ++ .../src/unit_tests/signature_tests.rs | 21 ++- .../src/unit_tests/vec_pack_tests.rs | 1 + .../src/ability_field_requirements.rs | 2 +- .../move-bytecode-verifier/src/absint.rs | 2 +- .../src/acquires_list_verifier.rs | 14 +- .../src/check_duplication.rs | 28 +-- .../src/dependencies.rs | 42 ++--- .../src/instantiation_loops.rs | 5 +- .../src/instruction_consistency.rs | 17 +- .../move-bytecode-verifier/src/limits.rs | 12 +- .../src/locals_safety/mod.rs | 14 ++ .../src/reference_safety/abstract_state.rs | 2 +- .../src/reference_safety/mod.rs | 14 ++ .../regression_tests/reference_analysis.rs | 35 ++-- .../move-bytecode-verifier/src/signature.rs | 44 +++-- .../src/stack_usage_verifier.rs | 14 ++ .../move-bytecode-verifier/src/struct_defs.rs | 10 +- .../move-bytecode-verifier/src/type_safety.rs | 29 +++- .../crates/move-vm-runtime/src/interpreter.rs | 13 +- .../v0/crates/move-vm-runtime/src/loader.rs | 148 +++++++++------- .../v0/crates/move-vm-runtime/src/session.rs | 6 +- .../src/unit_tests/vm_arguments_tests.rs | 31 ++-- .../bounds_tests.proptest-regressions | 8 +- .../src/unit_tests/bounds_tests.rs | 12 +- .../src/unit_tests/constants_tests.rs | 2 +- .../src/unit_tests/generic_ops_tests.rs | 39 +++-- .../src/unit_tests/large_type_test.rs | 5 + .../src/unit_tests/limit_tests.rs | 36 ++-- .../src/unit_tests/locals.rs | 3 + .../src/unit_tests/loop_summary_tests.rs | 158 ++++++++++------- .../src/unit_tests/many_back_edges.rs | 2 + .../src/unit_tests/mod.rs | 4 +- .../src/unit_tests/reference_safety_tests.rs | 11 ++ .../src/unit_tests/signature_tests.rs | 21 ++- .../src/unit_tests/vec_pack_tests.rs | 1 + .../src/ability_field_requirements.rs | 2 +- .../move-bytecode-verifier/src/absint.rs | 2 +- .../src/acquires_list_verifier.rs | 14 +- .../src/check_duplication.rs | 28 +-- .../src/dependencies.rs | 42 ++--- .../src/instantiation_loops.rs | 6 +- .../src/instruction_consistency.rs | 17 +- .../move-bytecode-verifier/src/limits.rs | 12 +- .../src/locals_safety/mod.rs | 14 ++ .../src/reference_safety/abstract_state.rs | 2 +- .../src/reference_safety/mod.rs | 14 ++ .../regression_tests/reference_analysis.rs | 35 ++-- .../move-bytecode-verifier/src/signature.rs | 44 +++-- .../src/stack_usage_verifier.rs | 14 ++ .../move-bytecode-verifier/src/struct_defs.rs | 10 +- .../move-bytecode-verifier/src/type_safety.rs | 31 +++- .../crates/move-vm-runtime/src/interpreter.rs | 13 +- .../v1/crates/move-vm-runtime/src/loader.rs | 155 ++++++++++------- .../v1/crates/move-vm-runtime/src/runtime.rs | 6 +- .../v1/crates/move-vm-runtime/src/session.rs | 6 +- .../src/unit_tests/vm_arguments_tests.rs | 31 ++-- .../src/unit_tests/bounds_tests.rs | 12 +- .../src/unit_tests/constants_tests.rs | 2 +- .../src/unit_tests/generic_ops_tests.rs | 39 +++-- .../src/unit_tests/large_type_test.rs | 5 + .../src/unit_tests/limit_tests.rs | 36 ++-- .../src/unit_tests/locals.rs | 3 + .../src/unit_tests/loop_summary_tests.rs | 158 ++++++++++------- .../src/unit_tests/many_back_edges.rs | 2 + .../src/unit_tests/mod.rs | 4 +- .../src/unit_tests/reference_safety_tests.rs | 11 ++ .../src/unit_tests/signature_tests.rs | 21 ++- .../src/unit_tests/vec_pack_tests.rs | 1 + .../src/ability_field_requirements.rs | 2 +- .../move-bytecode-verifier/src/absint.rs | 2 +- .../src/acquires_list_verifier.rs | 14 +- .../src/check_duplication.rs | 33 ++-- .../src/dependencies.rs | 44 ++--- .../src/instantiation_loops.rs | 4 +- .../src/instruction_consistency.rs | 17 +- .../move-bytecode-verifier/src/limits.rs | 12 +- .../src/locals_safety/mod.rs | 14 ++ .../src/reference_safety/abstract_state.rs | 2 +- .../src/reference_safety/mod.rs | 14 ++ .../regression_tests/reference_analysis.rs | 35 ++-- .../move-bytecode-verifier/src/signature.rs | 44 +++-- .../src/stack_usage_verifier.rs | 14 ++ .../move-bytecode-verifier/src/struct_defs.rs | 10 +- .../move-bytecode-verifier/src/type_safety.rs | 31 +++- .../crates/move-vm-runtime/src/interpreter.rs | 13 +- .../v2/crates/move-vm-runtime/src/loader.rs | 164 ++++++++++-------- .../v2/crates/move-vm-runtime/src/runtime.rs | 6 +- .../v2/crates/move-vm-runtime/src/session.rs | 6 +- .../src/unit_tests/vm_arguments_tests.rs | 31 ++-- 100 files changed, 1547 insertions(+), 843 deletions(-) diff --git a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.proptest-regressions b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.proptest-regressions index 6baf2ee61f189..3945bd370c9d0 100644 --- a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.proptest-regressions +++ b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.proptest-regressions @@ -4,7 +4,7 @@ # # It is recommended to check this file in to source control so that # everyone who runs the test benefits from these saved cases. -cc 2beb0a0e65962432af560e626fa109d269b07db8807968413425f0bb14bb3667 # shrinks to module = CompiledModule: { struct_handles: [ StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } -cc c14ae393a6eefae82c0f4ede2acaa0aa0e993c1bba3fe3e5958e6e31cb5d2957 # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] struct_handles: [ StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = [] -cc 88615e15ef42d29405cd91d6d0a573ccbeb833d0c7471f718ee794bc5ba399ca # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] struct_handles: [ StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 }, StructDefinition { struct_handle: 2, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = [OutOfBoundsMutation { src_kind: StructDefinition, src_idx: Index(0), dst_kind: FieldDefinition, offset: 0 }] -cc a34039f5d57751762a6eacf3ca3a2857781fb0bd0af0b7a06a9427f896f29aa9 # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] struct_handles: [ StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x2, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x0, code: CodeUnit { max_stack_size: 0, locals: 0 code: [ BrTrue(1),] } },] type_signatures: [ TypeSignature(Unit), TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = [] +cc 2beb0a0e65962432af560e626fa109d269b07db8807968413425f0bb14bb3667 # shrinks to module = CompiledModule: { datatype_handles: [ DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } +cc c14ae393a6eefae82c0f4ede2acaa0aa0e993c1bba3fe3e5958e6e31cb5d2957 # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] datatype_handles: [ DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = [] +cc 88615e15ef42d29405cd91d6d0a573ccbeb833d0c7471f718ee794bc5ba399ca # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] datatype_handles: [ DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 }, StructDefinition { struct_handle: 2, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = [OutOfBoundsMutation { src_kind: StructDefinition, src_idx: Index(0), dst_kind: FieldDefinition, offset: 0 }] +cc a34039f5d57751762a6eacf3ca3a2857781fb0bd0af0b7a06a9427f896f29aa9 # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] datatype_handles: [ DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x2, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x0, code: CodeUnit { max_stack_size: 0, locals: 0 code: [ BrTrue(1),] } },] type_signatures: [ TypeSignature(Unit), TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = [] diff --git a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.rs b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.rs index 905bc6540ba44..91bc085965a26 100644 --- a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.rs +++ b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.rs @@ -63,7 +63,7 @@ fn invalid_struct_in_fn_return_() { let mut m = basic_test_module(); m.function_handles[0].return_ = SignatureIndex(1); m.signatures - .push(Signature(vec![Struct(StructHandleIndex::new(1))])); + .push(Signature(vec![Datatype(DatatypeHandleIndex::new(1))])); assert_eq!( BoundsChecker::verify_module(&m).unwrap_err().major_status(), StatusCode::INDEX_OUT_OF_BOUNDS @@ -94,7 +94,7 @@ fn invalid_struct_in_field() { let mut m = basic_test_module(); match &mut m.struct_defs[0].field_information { StructFieldInformation::Declared(ref mut fields) => { - fields[0].signature.0 = Struct(StructHandleIndex::new(3)); + fields[0].signature.0 = Datatype(DatatypeHandleIndex::new(3)); assert_eq!( BoundsChecker::verify_module(&m).unwrap_err().major_status(), StatusCode::INDEX_OUT_OF_BOUNDS @@ -111,8 +111,8 @@ fn invalid_struct_with_actuals_in_field() { let mut m = basic_test_module(); match &mut m.struct_defs[0].field_information { StructFieldInformation::Declared(ref mut fields) => { - fields[0].signature.0 = StructInstantiation(Box::new(( - StructHandleIndex::new(0), + fields[0].signature.0 = DatatypeInstantiation(Box::new(( + DatatypeHandleIndex::new(0), vec![TypeParameter(0)], ))); assert_eq!( @@ -167,7 +167,7 @@ fn invalid_struct_as_type_actual_in_exists() { let mut m = basic_test_module(); m.signatures - .push(Signature(vec![Struct(StructHandleIndex::new(3))])); + .push(Signature(vec![Datatype(DatatypeHandleIndex::new(3))])); m.function_instantiations.push(FunctionInstantiation { handle: FunctionHandleIndex::new(0), type_parameters: SignatureIndex::new(1), @@ -239,7 +239,7 @@ fn invalid_struct_for_vector_operation() { let mut skeleton = basic_test_module(); skeleton .signatures - .push(Signature(vec![Struct(StructHandleIndex::new(3))])); + .push(Signature(vec![Datatype(DatatypeHandleIndex::new(3))])); let sig_index = SignatureIndex((skeleton.signatures.len() - 1) as u16); for bytecode in [ VecPack(sig_index, 0), diff --git a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/constants_tests.rs b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/constants_tests.rs index 653654119714d..c3e43fb3b896b 100644 --- a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/constants_tests.rs +++ b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/constants_tests.rs @@ -238,7 +238,7 @@ fn invalid_types() { // TODO cannot check structs are banned currently. This can be handled by IR and source lang // tests - // invalid_type(SignatureToken::Struct(StructHandleIndex(0)), vec![0]); + // invalid_type(SignatureToken::Datatype(DatatypeHandleIndex(0)), vec![0]); } fn tvec(s: SignatureToken) -> SignatureToken { diff --git a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/generic_ops_tests.rs b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/generic_ops_tests.rs index 92ab3aa12cba5..aec9fdbe19549 100644 --- a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/generic_ops_tests.rs +++ b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/generic_ops_tests.rs @@ -36,33 +36,33 @@ fn make_module() -> CompiledModule { address_identifiers: vec![ AccountAddress::ZERO, // Module address ], - struct_handles: vec![ - StructHandle { + datatype_handles: vec![ + DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(1), abilities: AbilitySet::PRIMITIVES, type_parameters: vec![], }, - StructHandle { + DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(2), abilities: AbilitySet::PRIMITIVES, - type_parameters: vec![StructTypeParameter { + type_parameters: vec![DatatypeTyParameter { constraints: AbilitySet::PRIMITIVES, is_phantom: false, }], }, - StructHandle { + DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(3), abilities: AbilitySet::EMPTY | Ability::Key, type_parameters: vec![], }, - StructHandle { + DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(4), abilities: AbilitySet::EMPTY | Ability::Key, - type_parameters: vec![StructTypeParameter { + type_parameters: vec![DatatypeTyParameter { constraints: AbilitySet::PRIMITIVES, is_phantom: false, }], @@ -71,7 +71,7 @@ fn make_module() -> CompiledModule { struct_defs: vec![ // struct S { f: u64 } StructDefinition { - struct_handle: StructHandleIndex(0), + struct_handle: DatatypeHandleIndex(0), field_information: StructFieldInformation::Declared(vec![FieldDefinition { name: IdentifierIndex(5), signature: TypeSignature(SignatureToken::U64), @@ -79,7 +79,7 @@ fn make_module() -> CompiledModule { }, // struct GS { f: T } StructDefinition { - struct_handle: StructHandleIndex(1), + struct_handle: DatatypeHandleIndex(1), field_information: StructFieldInformation::Declared(vec![FieldDefinition { name: IdentifierIndex(5), signature: TypeSignature(SignatureToken::TypeParameter(0)), @@ -87,7 +87,7 @@ fn make_module() -> CompiledModule { }, // struct R has key { f: u64 } StructDefinition { - struct_handle: StructHandleIndex(2), + struct_handle: DatatypeHandleIndex(2), field_information: StructFieldInformation::Declared(vec![FieldDefinition { name: IdentifierIndex(5), signature: TypeSignature(SignatureToken::U64), @@ -95,7 +95,7 @@ fn make_module() -> CompiledModule { }, // struct GR has key { f: T } StructDefinition { - struct_handle: StructHandleIndex(3), + struct_handle: DatatypeHandleIndex(3), field_information: StructFieldInformation::Declared(vec![FieldDefinition { name: IdentifierIndex(5), signature: TypeSignature(SignatureToken::TypeParameter(0)), @@ -138,6 +138,7 @@ fn make_module() -> CompiledModule { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Ret], + jump_tables: vec![], }), }, // fun g_fn() { return; } @@ -149,6 +150,7 @@ fn make_module() -> CompiledModule { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Ret], + jump_tables: vec![], }), }, // fun test_fn() { ... } - tests will fill up the code @@ -160,6 +162,7 @@ fn make_module() -> CompiledModule { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![], + jump_tables: vec![], }), }, ], @@ -180,6 +183,10 @@ fn make_module() -> CompiledModule { struct_def_instantiations: vec![], function_instantiations: vec![], field_instantiations: vec![], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], } } @@ -193,6 +200,7 @@ fn generic_call_to_non_generic_func() { Bytecode::CallGeneric(FunctionInstantiationIndex(0)), Bytecode::Ret, ], + jump_tables: vec![], }); module.function_instantiations.push(FunctionInstantiation { handle: FunctionHandleIndex(0), @@ -214,6 +222,7 @@ fn non_generic_call_to_generic_func() { module.function_defs[2].code = Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(1)), Bytecode::Ret], + jump_tables: vec![], }); let err = InstructionConsistency::verify_module(&module) .expect_err("Call to generic function must fail"); @@ -235,6 +244,7 @@ fn generic_pack_on_non_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module .struct_def_instantiations @@ -263,6 +273,7 @@ fn non_generic_pack_on_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); let err = InstructionConsistency::verify_module(&module) .expect_err("Pack to generic struct must fail"); @@ -285,6 +296,7 @@ fn generic_unpack_on_non_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module .struct_def_instantiations @@ -314,6 +326,7 @@ fn non_generic_unpack_on_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module .struct_def_instantiations @@ -343,6 +356,7 @@ fn generic_mut_borrow_field_on_non_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module.field_instantiations.push(FieldInstantiation { handle: FieldHandleIndex(0), @@ -374,6 +388,7 @@ fn non_generic_mut_borrow_field_on_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module .struct_def_instantiations @@ -407,6 +422,7 @@ fn generic_borrow_field_on_non_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module.field_instantiations.push(FieldInstantiation { handle: FieldHandleIndex(0), @@ -438,6 +454,7 @@ fn non_generic_borrow_field_on_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module .struct_def_instantiations diff --git a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/large_type_test.rs b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/large_type_test.rs index 70953906af9bd..23b8c452d8915 100644 --- a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/large_type_test.rs +++ b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/large_type_test.rs @@ -48,6 +48,7 @@ fn test_large_types() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(0)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -68,6 +69,7 @@ fn test_large_types() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(1)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -89,6 +91,7 @@ fn test_large_types() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(1)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -109,6 +112,7 @@ fn test_large_types() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Ret], + jump_tables: vec![], }), }); @@ -131,6 +135,7 @@ fn test_large_types() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![], + jump_tables: vec![], }), }); diff --git a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/limit_tests.rs b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/limit_tests.rs index b30eaea22f91c..e7eda3d0ed084 100644 --- a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/limit_tests.rs +++ b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/limit_tests.rs @@ -38,11 +38,11 @@ fn test_function_handle_type_instantiation() { #[test] fn test_struct_handle_type_instantiation() { let mut m = basic_test_module(); - m.struct_handles.push(StructHandle { + m.datatype_handles.push(DatatypeHandle { module: ModuleHandleIndex::new(0), name: IdentifierIndex::new(0), abilities: AbilitySet::ALL, - type_parameters: std::iter::repeat(StructTypeParameter { + type_parameters: std::iter::repeat(DatatypeTyParameter { constraints: AbilitySet::ALL, is_phantom: false, }) @@ -97,7 +97,7 @@ fn big_vec_unpacks() { const N_TYPE_PARAMS: usize = 16; let mut st = SignatureToken::Vector(Box::new(SignatureToken::U8)); let type_params = vec![st; N_TYPE_PARAMS]; - st = SignatureToken::StructInstantiation(Box::new((StructHandleIndex(0), type_params))); + st = SignatureToken::DatatypeInstantiation(Box::new((DatatypeHandleIndex(0), type_params))); const N_VEC_PUSH: u16 = 1000; let mut code = vec![]; // 1. CopyLoc: ... -> ... st @@ -115,7 +115,7 @@ fn big_vec_unpacks() { code.push(Bytecode::Pop); } code.push(Bytecode::Ret); - let type_param_constraints = StructTypeParameter { + let type_param_constraints = DatatypeTyParameter { constraints: AbilitySet::EMPTY, is_phantom: false, }; @@ -126,7 +126,7 @@ fn big_vec_unpacks() { address: AddressIdentifierIndex(0), name: IdentifierIndex(0), }], - struct_handles: vec![StructHandle { + datatype_handles: vec![DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(1), abilities: AbilitySet::ALL, @@ -153,7 +153,7 @@ fn big_vec_unpacks() { constant_pool: vec![], metadata: vec![], struct_defs: vec![StructDefinition { - struct_handle: StructHandleIndex(0), + struct_handle: DatatypeHandleIndex(0), field_information: StructFieldInformation::Native, }], function_defs: vec![FunctionDefinition { @@ -164,8 +164,13 @@ fn big_vec_unpacks() { code: Some(CodeUnit { locals: SignatureIndex(0), code, + jump_tables: vec![], }), }], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; // save module and verify that it can ser/de @@ -199,7 +204,7 @@ const MAX_FUNCTIONS: usize = 1000; #[test] fn max_struct_test() { let config = VerifierConfig { - max_struct_definitions: Some(MAX_STRUCTS), + max_data_definitions: Some(MAX_STRUCTS), max_fields_in_struct: Some(MAX_FIELDS), max_function_definitions: Some(MAX_FUNCTIONS), ..Default::default() @@ -238,7 +243,7 @@ fn max_struct_test() { #[test] fn max_fields_test() { let config = VerifierConfig { - max_struct_definitions: Some(MAX_STRUCTS), + max_data_definitions: Some(MAX_STRUCTS), max_fields_in_struct: Some(MAX_FIELDS), max_function_definitions: Some(MAX_FUNCTIONS), ..Default::default() @@ -303,7 +308,7 @@ fn max_fields_test() { #[test] fn max_functions_test() { let config = VerifierConfig { - max_struct_definitions: Some(MAX_STRUCTS), + max_data_definitions: Some(MAX_STRUCTS), max_fields_in_struct: Some(MAX_FIELDS), max_function_definitions: Some(MAX_FUNCTIONS), ..Default::default() @@ -348,7 +353,7 @@ fn max_functions_test() { #[test] fn max_mixed_config_test() { let config = VerifierConfig { - max_struct_definitions: Some(MAX_STRUCTS), + max_data_definitions: Some(MAX_STRUCTS), max_fields_in_struct: Some(MAX_FIELDS), max_function_definitions: Some(MAX_FUNCTIONS), ..Default::default() @@ -362,7 +367,7 @@ fn max_mixed_config_test() { let config = VerifierConfig { max_function_definitions: None, - max_struct_definitions: None, + max_data_definitions: None, max_fields_in_struct: None, ..Default::default() }; @@ -392,7 +397,7 @@ fn max_mixed_config_test() { assert_eq!(res, Ok(())); let config = VerifierConfig { - max_struct_definitions: Some(MAX_STRUCTS), + max_data_definitions: Some(MAX_STRUCTS), max_fields_in_struct: Some(MAX_FIELDS), ..Default::default() }; @@ -434,7 +439,7 @@ fn max_mixed_config_test() { ); let config = VerifierConfig { - max_struct_definitions: Some(MAX_STRUCTS), + max_data_definitions: Some(MAX_STRUCTS), max_function_definitions: Some(MAX_FUNCTIONS), ..Default::default() }; @@ -739,14 +744,14 @@ fn multi_struct(module: &mut CompiledModule, count: usize) { module .identifiers .push(Identifier::new(format!("A_{}", i)).unwrap()); - module.struct_handles.push(StructHandle { + module.datatype_handles.push(DatatypeHandle { module: module.self_module_handle_idx, name: IdentifierIndex((module.identifiers.len() - 1) as u16), abilities: AbilitySet::EMPTY, type_parameters: vec![], }); module.struct_defs.push(StructDefinition { - struct_handle: StructHandleIndex((module.struct_handles.len() - 1) as u16), + struct_handle: DatatypeHandleIndex((module.datatype_handles.len() - 1) as u16), field_information: StructFieldInformation::Declared(vec![]), }); } @@ -806,6 +811,7 @@ fn multi_functions(module: &mut CompiledModule, count: usize) { code: Some(CodeUnit { locals: SignatureIndex((module.signatures.len() - 1) as u16), code: vec![Bytecode::Ret], + jump_tables: vec![], }), }); } diff --git a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/locals.rs b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/locals.rs index 6451e165a7232..c4e5a51558fe1 100644 --- a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/locals.rs +++ b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/locals.rs @@ -35,6 +35,7 @@ fn test_locals() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Ret], + jump_tables: vec![], }), }); @@ -67,6 +68,7 @@ fn test_locals() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::LdTrue, Bytecode::LdU8(0), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -89,6 +91,7 @@ fn test_locals() { code: Some(CodeUnit { locals: SignatureIndex(1), code: vec![], + jump_tables: vec![], }), }); diff --git a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/loop_summary_tests.rs b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/loop_summary_tests.rs index 819b9412709b9..a837f295ae398 100644 --- a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/loop_summary_tests.rs +++ b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/loop_summary_tests.rs @@ -23,13 +23,16 @@ macro_rules! assert_node { fn linear_summary() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ Nop, - /* */ Branch(2), - /* B2, L1 */ Nop, - /* */ Branch(4), - /* B4, L2 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ Nop, + /* */ Branch(2), + /* B2, L1 */ Nop, + /* */ Branch(4), + /* B4, L2 */ Ret, + ], + &[], + )) }; let n: Vec<_> = summary.preorder().collect(); @@ -65,12 +68,15 @@ fn linear_summary() { fn non_loop_back_branch_summary() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ Nop, - /* */ Branch(3), - /* B2, L2 */ Ret, - /* B3, L1 */ Branch(2), - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ Nop, + /* */ Branch(3), + /* B2, L2 */ Ret, + /* B3, L1 */ Branch(2), + ], + &[], + )) }; let n: Vec<_> = summary.preorder().collect(); @@ -106,12 +112,15 @@ fn non_loop_back_branch_summary() { fn branching_summary() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ LdTrue, - /* */ BrTrue(3), - /* B2, L2 */ Nop, - /* B3, L1 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ LdTrue, + /* */ BrTrue(3), + /* B2, L2 */ Nop, + /* B3, L1 */ Ret, + ], + &[], + )) }; let n: Vec<_> = summary.preorder().collect(); @@ -151,13 +160,16 @@ fn branching_summary() { fn looping_summary() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ LdTrue, - /* */ BrTrue(4), - /* B2, L2 */ Nop, - /* */ Branch(0), - /* B4, L1 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ LdTrue, + /* */ BrTrue(4), + /* B2, L2 */ Nop, + /* */ Branch(0), + /* B4, L1 */ Ret, + ], + &[], + )) }; let n: Vec<_> = summary.preorder().collect(); @@ -193,14 +205,17 @@ fn looping_summary() { fn branches_in_loops_summary() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ LdTrue, - /* */ BrTrue(3), - /* B2, L3 */ Nop, - /* B3, L1 */ LdFalse, - /* */ BrFalse(0), - /* B5, L2 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ LdTrue, + /* */ BrTrue(3), + /* B2, L3 */ Nop, + /* B3, L1 */ LdFalse, + /* */ BrFalse(0), + /* B5, L2 */ Ret, + ], + &[], + )) }; let n: Vec<_> = summary.preorder().collect(); @@ -244,22 +259,25 @@ fn branches_in_loops_summary() { fn loops_in_branches_summary() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ LdTrue, - /* */ BrTrue(8), - /* B2, L5 */ Nop, - /* B3, L6 */ LdFalse, - /* */ BrFalse(3), - /* B5, L7 */ LdTrue, - /* */ BrTrue(2), - /* B7, L8 */ Branch(13), - /* B8, L1 */ Nop, - /* B9, L2 */ LdTrue, - /* */ BrTrue(8), - /* B11, L3 */ LdFalse, - /* */ BrFalse(9), - /* B13, L4 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ LdTrue, + /* */ BrTrue(8), + /* B2, L5 */ Nop, + /* B3, L6 */ LdFalse, + /* */ BrFalse(3), + /* B5, L7 */ LdTrue, + /* */ BrTrue(2), + /* B7, L8 */ Branch(13), + /* B8, L1 */ Nop, + /* B9, L2 */ LdTrue, + /* */ BrTrue(8), + /* B11, L3 */ LdFalse, + /* */ BrFalse(9), + /* B13, L4 */ Ret, + ], + &[], + )) }; let n: Vec<_> = summary.preorder().collect(); @@ -343,13 +361,16 @@ fn loops_in_branches_summary() { fn loop_collapsing() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ LdTrue, - /* */ BrTrue(4), - /* B2, L2 */ Nop, - /* */ Branch(0), - /* B4, L1 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ LdTrue, + /* */ BrTrue(4), + /* B2, L2 */ Nop, + /* */ Branch(0), + /* B4, L1 */ Ret, + ], + &[], + )) }; let mut partition = LoopPartition::new(&summary); @@ -369,16 +390,19 @@ fn loop_collapsing() { fn nested_loop_collapsing() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ Nop, - /* B1, L1 */ LdTrue, - /* */ BrTrue(1), - /* B3, L2 */ LdFalse, - /* */ BrFalse(0), - /* B5, L3 */ LdTrue, - /* */ BrTrue(0), - /* B7, L4 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ Nop, + /* B1, L1 */ LdTrue, + /* */ BrTrue(1), + /* B3, L2 */ LdFalse, + /* */ BrFalse(0), + /* B5, L3 */ LdTrue, + /* */ BrTrue(0), + /* B7, L4 */ Ret, + ], + &[], + )) }; let mut partition = LoopPartition::new(&summary); diff --git a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/many_back_edges.rs b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/many_back_edges.rs index fe527fcbdf0f5..feda780b5cf93 100644 --- a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/many_back_edges.rs +++ b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/many_back_edges.rs @@ -46,6 +46,7 @@ fn many_backedges() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::LdTrue, Bytecode::LdU8(0), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -68,6 +69,7 @@ fn many_backedges() { code: Some(CodeUnit { locals: SignatureIndex(1), code: vec![], + jump_tables: vec![], }), }); diff --git a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/mod.rs b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/mod.rs index 3238641a6e76e..0ebd1d0fee366 100644 --- a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/mod.rs +++ b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/mod.rs @@ -2,6 +2,7 @@ // Copyright (c) The Move Contributors // SPDX-License-Identifier: Apache-2.0 +use move_core_types::VARIANT_COUNT_MAX; use move_vm_config::verifier::{ MeterConfig, VerifierConfig, DEFAULT_MAX_CONSTANT_VECTOR_LEN, DEFAULT_MAX_IDENTIFIER_LENGTH, }; @@ -36,7 +37,7 @@ pub(crate) fn production_config() -> (VerifierConfig, MeterConfig) { max_type_nodes: Some(256), max_push_size: Some(10000), max_dependency_depth: Some(100), - max_struct_definitions: Some(200), + max_data_definitions: Some(200), max_fields_in_struct: Some(30), max_function_definitions: Some(1000), @@ -48,6 +49,7 @@ pub(crate) fn production_config() -> (VerifierConfig, MeterConfig) { max_idenfitier_len: Some(DEFAULT_MAX_IDENTIFIER_LENGTH), allow_receiving_object_id: true, reject_mutable_random_on_entry_functions: true, + max_variants_in_enum: Some(VARIANT_COUNT_MAX), }, MeterConfig::default(), ) diff --git a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/reference_safety_tests.rs b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/reference_safety_tests.rs index 2fff034c142af..567364efe296c 100644 --- a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/reference_safety_tests.rs +++ b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/reference_safety_tests.rs @@ -35,6 +35,7 @@ fn test_bicliques() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(0)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -61,6 +62,7 @@ fn test_bicliques() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![], + jump_tables: vec![], }), }); let code = &mut m.function_defs[1].code.as_mut().unwrap().code; @@ -87,6 +89,7 @@ fn test_bicliques() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Ret], + jump_tables: vec![], }), }); @@ -109,6 +112,7 @@ fn test_bicliques() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![], + jump_tables: vec![], }), }); let code = &mut m.function_defs[i as usize + 2].code.as_mut().unwrap().code; @@ -160,6 +164,7 @@ fn test_merge_state_large_graph() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(0)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -185,6 +190,7 @@ fn test_merge_state_large_graph() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(1)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -205,6 +211,7 @@ fn test_merge_state_large_graph() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(1)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -226,6 +233,7 @@ fn test_merge_state_large_graph() { code: Some(CodeUnit { locals: SignatureIndex(1), code: vec![], + jump_tables: vec![], }), }); let code = &mut m.function_defs[i as usize + 3].code.as_mut().unwrap().code; @@ -282,6 +290,7 @@ fn test_merge_state() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(0)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -313,6 +322,7 @@ fn test_merge_state() { code: Some(CodeUnit { locals: SignatureIndex(2), code: vec![], + jump_tables: vec![], }), }); let code = &mut m.function_defs[i as usize + 1].code.as_mut().unwrap().code; @@ -395,6 +405,7 @@ fn test_copyloc_pop() { code: Some(CodeUnit { locals: SignatureIndex(2), code: vec![], + jump_tables: vec![], }), }); let code = &mut m.function_defs[i as usize].code.as_mut().unwrap().code; diff --git a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/signature_tests.rs b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/signature_tests.rs index 41d2d4e541081..2cfcc14aa176d 100644 --- a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/signature_tests.rs +++ b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/signature_tests.rs @@ -33,7 +33,7 @@ fn no_verify_locals_good() { name: IdentifierIndex(0), }], self_module_handle_idx: ModuleHandleIndex(0), - struct_handles: vec![], + datatype_handles: vec![], signatures: vec![ Signature(vec![Address]), Signature(vec![U64]), @@ -78,6 +78,7 @@ fn no_verify_locals_good() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Ret], + jump_tables: vec![], }), }, FunctionDefinition { @@ -88,9 +89,14 @@ fn no_verify_locals_good() { code: Some(CodeUnit { locals: SignatureIndex(1), code: vec![Ret], + jump_tables: vec![], }), }, ], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; assert!(verify_module_unmetered(&compiled_module_good).is_ok()); } @@ -106,7 +112,7 @@ fn big_signature_test() { } for _ in 0..INSTANTIATION_DEPTH { let type_params = vec![st; N_TYPE_PARAMS]; - st = SignatureToken::StructInstantiation(Box::new((StructHandleIndex(0), type_params))); + st = SignatureToken::DatatypeInstantiation(Box::new((DatatypeHandleIndex(0), type_params))); } const N_READPOP: u16 = 7500; @@ -122,7 +128,7 @@ fn big_signature_test() { } code.push(Bytecode::Ret); - let type_param_constraints = StructTypeParameter { + let type_param_constraints = DatatypeTyParameter { constraints: AbilitySet::EMPTY, is_phantom: false, }; @@ -134,7 +140,7 @@ fn big_signature_test() { address: AddressIdentifierIndex(0), name: IdentifierIndex(0), }], - struct_handles: vec![StructHandle { + datatype_handles: vec![DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(1), abilities: AbilitySet::ALL, @@ -161,7 +167,7 @@ fn big_signature_test() { constant_pool: vec![], metadata: vec![], struct_defs: vec![StructDefinition { - struct_handle: StructHandleIndex(0), + struct_handle: DatatypeHandleIndex(0), field_information: StructFieldInformation::Native, }], function_defs: vec![FunctionDefinition { @@ -172,8 +178,13 @@ fn big_signature_test() { code: Some(CodeUnit { locals: SignatureIndex(0), code, + jump_tables: vec![], }), }], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; // save module and verify that it can ser/de diff --git a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/vec_pack_tests.rs b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/vec_pack_tests.rs index 540962b3cbb24..96667cee33f04 100644 --- a/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/vec_pack_tests.rs +++ b/external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/vec_pack_tests.rs @@ -32,6 +32,7 @@ fn test_vec_pack() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![], + jump_tables: vec![], }), }); diff --git a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/ability_field_requirements.rs b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/ability_field_requirements.rs index e90c86efae4c5..5ef60518b65ae 100644 --- a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/ability_field_requirements.rs +++ b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/ability_field_requirements.rs @@ -17,7 +17,7 @@ pub fn verify_module(module: &CompiledModule) -> VMResult<()> { fn verify_module_impl(module: &CompiledModule) -> PartialVMResult<()> { for (idx, struct_def) in module.struct_defs().iter().enumerate() { - let sh = module.struct_handle_at(struct_def.struct_handle); + let sh = module.datatype_handle_at(struct_def.struct_handle); let fields = match &struct_def.field_information { StructFieldInformation::Native => continue, StructFieldInformation::Declared(fields) => fields, diff --git a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/absint.rs b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/absint.rs index 9f11fb5f7d37f..e9cad4ff0556b 100644 --- a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/absint.rs +++ b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/absint.rs @@ -194,7 +194,7 @@ impl<'a> FunctionContext<'a> { return_: module.signature_at(function_handle.return_), locals: module.signature_at(code.locals), type_parameters: &function_handle.type_parameters, - cfg: VMControlFlowGraph::new(&code.code), + cfg: VMControlFlowGraph::new(&code.code, &code.jump_tables), } } diff --git a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/acquires_list_verifier.rs b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/acquires_list_verifier.rs index cab0b6b9a6456..743bb4335baa5 100644 --- a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/acquires_list_verifier.rs +++ b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/acquires_list_verifier.rs @@ -72,7 +72,7 @@ impl<'a> AcquiresVerifier<'a> { } let struct_def = safe_unwrap!(module.struct_defs().get(annotation.0 as usize)); - let struct_handle = module.struct_handle_at(struct_def.struct_handle); + let struct_handle = module.datatype_handle_at(struct_def.struct_handle); if !struct_handle.abilities.has_key() { return Err(PartialVMError::new(StatusCode::INVALID_ACQUIRES_ANNOTATION)); } @@ -171,6 +171,18 @@ impl<'a> AcquiresVerifier<'a> { | Bytecode::VecPopBack(_) | Bytecode::VecUnpack(..) | Bytecode::VecSwap(_) => Ok(()), + Bytecode::PackVariant(_) + | Bytecode::PackVariantGeneric(_) + | Bytecode::UnpackVariant(_) + | Bytecode::UnpackVariantGeneric(_) + | Bytecode::UnpackVariantImmRef(_) + | Bytecode::UnpackVariantGenericImmRef(_) + | Bytecode::UnpackVariantMutRef(_) + | Bytecode::UnpackVariantGenericMutRef(_) + | Bytecode::VariantSwitch(_) => Err(PartialVMError::new( + StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR, + ) + .with_message("Unexpected variant opcode in version 0".to_string())), } } diff --git a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/check_duplication.rs b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/check_duplication.rs index 6e26a4b63b15e..c44fe9ba50cb2 100644 --- a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/check_duplication.rs +++ b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/check_duplication.rs @@ -13,7 +13,7 @@ use move_binary_format::{ errors::{verification_error, Location, PartialVMResult, VMResult}, file_format::{ CompiledModule, Constant, FunctionHandle, FunctionHandleIndex, FunctionInstantiation, - ModuleHandle, Signature, StructFieldInformation, StructHandle, StructHandleIndex, + ModuleHandle, Signature, StructFieldInformation, DatatypeHandle, DatatypeHandleIndex, TableIndex, }, IndexKind, @@ -39,7 +39,7 @@ impl<'a> DuplicationChecker<'a> { Self::check_signatures(module.signatures())?; Self::check_module_handles(module.module_handles())?; Self::check_module_handles(module.friend_decls())?; - Self::check_struct_handles(module.struct_handles())?; + Self::check_datatype_handles(module.datatype_handles())?; Self::check_function_handles(module.function_handles())?; Self::check_function_instantiations(module.function_instantiations())?; @@ -106,12 +106,12 @@ impl<'a> DuplicationChecker<'a> { } } - // StructHandles - module and name define uniqueness - fn check_struct_handles(struct_handles: &[StructHandle]) -> PartialVMResult<()> { - match Self::first_duplicate_element(struct_handles.iter().map(|x| (x.module, x.name))) { + // DatatypeHandles - module and name define uniqueness + fn check_datatype_handles(datatype_handles: &[DatatypeHandle]) -> PartialVMResult<()> { + match Self::first_duplicate_element(datatype_handles.iter().map(|x| (x.module, x.name))) { Some(idx) => Err(verification_error( StatusCode::DUPLICATE_ELEMENT, - IndexKind::StructHandle, + IndexKind::DatatypeHandle, idx, )), None => Ok(()), @@ -181,7 +181,7 @@ impl<'a> DuplicationChecker<'a> { } fn check_struct_definitions(&self) -> PartialVMResult<()> { - // StructDefinition - contained StructHandle defines uniqueness + // StructDefinition - contained DatatypeHandle defines uniqueness if let Some(idx) = Self::first_duplicate_element(self.module.struct_defs().iter().map(|x| x.struct_handle)) { @@ -214,7 +214,7 @@ impl<'a> DuplicationChecker<'a> { } // Check that each struct definition is pointing to the self module if let Some(idx) = self.module.struct_defs().iter().position(|x| { - self.module.struct_handle_at(x.struct_handle).module != self.module.self_handle_idx() + self.module.datatype_handle_at(x.struct_handle).module != self.module.self_handle_idx() }) { return Err(verification_error( StatusCode::INVALID_MODULE_HANDLE, @@ -223,20 +223,20 @@ impl<'a> DuplicationChecker<'a> { )); } // Check that each struct handle in self module is implemented (has a declaration) - let implemented_struct_handles: HashSet = self + let implemented_datatype_handles: HashSet = self .module .struct_defs() .iter() .map(|x| x.struct_handle) .collect(); - if let Some(idx) = (0..self.module.struct_handles().len()).position(|x| { - let y = StructHandleIndex::new(x as u16); - self.module.struct_handle_at(y).module == self.module.self_handle_idx() - && !implemented_struct_handles.contains(&y) + if let Some(idx) = (0..self.module.datatype_handles().len()).position(|x| { + let y = DatatypeHandleIndex::new(x as u16); + self.module.datatype_handle_at(y).module == self.module.self_handle_idx() + && !implemented_datatype_handles.contains(&y) }) { return Err(verification_error( StatusCode::UNIMPLEMENTED_HANDLE, - IndexKind::StructHandle, + IndexKind::DatatypeHandle, idx as TableIndex, )); } diff --git a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/dependencies.rs b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/dependencies.rs index fec9f3c3f232f..e09d59c0b1e8c 100644 --- a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/dependencies.rs +++ b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/dependencies.rs @@ -6,9 +6,9 @@ use move_binary_format::{ errors::{verification_error, Location, PartialVMError, PartialVMResult, VMResult}, file_format::{ - AbilitySet, Bytecode, CodeOffset, CompiledModule, FunctionDefinitionIndex, - FunctionHandleIndex, ModuleHandleIndex, SignatureToken, StructHandleIndex, - StructTypeParameter, TableIndex, Visibility, + AbilitySet, Bytecode, CodeOffset, CompiledModule, DatatypeHandleIndex, DatatypeTyParameter, + FunctionDefinitionIndex, FunctionHandleIndex, ModuleHandleIndex, SignatureToken, + TableIndex, Visibility, }, file_format_common::VERSION_5, safe_unwrap, IndexKind, @@ -21,7 +21,7 @@ struct Context<'a, 'b> { // (Module -> CompiledModule) for (at least) all immediate dependencies dependency_map: BTreeMap, // (Module::StructName -> handle) for all types of all dependencies - struct_id_to_handle_map: BTreeMap<(ModuleId, Identifier), StructHandleIndex>, + struct_id_to_handle_map: BTreeMap<(ModuleId, Identifier), DatatypeHandleIndex>, // (Module::FunctionName -> handle) for all functions that can ever be called by this // module/script in all dependencies func_id_to_handle_map: BTreeMap<(ModuleId, Identifier), FunctionHandleIndex>, @@ -73,7 +73,7 @@ impl<'a, 'b> Context<'a, 'b> { // Module::StructName -> def handle idx for struct_def in module.struct_defs() { - let struct_handle = module.struct_handle_at(struct_def.struct_handle); + let struct_handle = module.datatype_handle_at(struct_def.struct_handle); let struct_name = module.identifier_at(struct_handle.name); context.struct_id_to_handle_map.insert( (module_id.clone(), struct_name.to_owned()), @@ -184,7 +184,7 @@ fn verify_imported_modules(context: &Context) -> PartialVMResult<()> { fn verify_imported_structs(context: &Context) -> PartialVMResult<()> { let self_module = context.resolver.self_handle_idx(); - for (idx, struct_handle) in context.resolver.struct_handles().iter().enumerate() { + for (idx, struct_handle) in context.resolver.datatype_handles().iter().enumerate() { if struct_handle.module == self_module { continue; } @@ -199,7 +199,7 @@ fn verify_imported_structs(context: &Context) -> PartialVMResult<()> { .get(&(owner_module_id, struct_name.to_owned())) { Some(def_idx) => { - let def_handle = owner_module.struct_handle_at(*def_idx); + let def_handle = owner_module.datatype_handle_at(*def_idx); if !compatible_struct_abilities(struct_handle.abilities, def_handle.abilities) || !compatible_struct_type_parameters( &struct_handle.type_parameters, @@ -208,7 +208,7 @@ fn verify_imported_structs(context: &Context) -> PartialVMResult<()> { { return Err(verification_error( StatusCode::TYPE_MISMATCH, - IndexKind::StructHandle, + IndexKind::DatatypeHandle, idx as TableIndex, )); } @@ -216,7 +216,7 @@ fn verify_imported_structs(context: &Context) -> PartialVMResult<()> { None => { return Err(verification_error( StatusCode::LOOKUP_FAILED, - IndexKind::StructHandle, + IndexKind::DatatypeHandle, idx as TableIndex, )) } @@ -345,8 +345,8 @@ fn compatible_fun_type_parameters( // - The number of type parameters must be the same // - Each pair of parameters must satisfy [`compatible_type_parameter_constraints`] and [`compatible_type_parameter_phantom_decl`] fn compatible_struct_type_parameters( - local_type_parameters_declaration: &[StructTypeParameter], - defined_type_parameters: &[StructTypeParameter], + local_type_parameters_declaration: &[DatatypeTyParameter], + defined_type_parameters: &[DatatypeTyParameter], ) -> bool { local_type_parameters_declaration.len() == defined_type_parameters.len() && local_type_parameters_declaration @@ -378,8 +378,8 @@ fn compatible_type_parameter_constraints( // Adding phantom declarations relaxes the requirements for clients, thus, the local view may // lack a phantom declaration present in the definition. fn compatible_type_parameter_phantom_decl( - local_type_parameter_declaration: &StructTypeParameter, - defined_type_parameter: &StructTypeParameter, + local_type_parameter_declaration: &DatatypeTyParameter, + defined_type_parameter: &DatatypeTyParameter, ) -> bool { // local_type_parameter_declaration.is_phantom => defined_type_parameter.is_phantom !local_type_parameter_declaration.is_phantom || defined_type_parameter.is_phantom @@ -419,10 +419,10 @@ fn compare_types( (SignatureToken::Vector(ty1), SignatureToken::Vector(ty2)) => { compare_types(context, ty1, ty2, def_module) } - (SignatureToken::Struct(idx1), SignatureToken::Struct(idx2)) => { + (SignatureToken::Datatype(idx1), SignatureToken::Datatype(idx2)) => { compare_structs(context, *idx1, *idx2, def_module) } - (SignatureToken::StructInstantiation(s1), SignatureToken::StructInstantiation(s2)) => { + (SignatureToken::DatatypeInstantiation(s1), SignatureToken::DatatypeInstantiation(s2)) => { let (idx1, inst1) = &**s1; let (idx2, inst2) = &**s2; compare_structs(context, *idx1, *idx2, def_module)?; @@ -446,8 +446,8 @@ fn compare_types( | (SignatureToken::Address, _) | (SignatureToken::Signer, _) | (SignatureToken::Vector(_), _) - | (SignatureToken::Struct(_), _) - | (SignatureToken::StructInstantiation(_), _) + | (SignatureToken::Datatype(_), _) + | (SignatureToken::DatatypeInstantiation(_), _) | (SignatureToken::Reference(_), _) | (SignatureToken::MutableReference(_), _) | (SignatureToken::TypeParameter(_), _) @@ -459,18 +459,18 @@ fn compare_types( fn compare_structs( context: &Context, - idx1: StructHandleIndex, - idx2: StructHandleIndex, + idx1: DatatypeHandleIndex, + idx2: DatatypeHandleIndex, def_module: &CompiledModule, ) -> PartialVMResult<()> { // grab ModuleId and struct name for the module being verified - let struct_handle = context.resolver.struct_handle_at(idx1); + let struct_handle = context.resolver.datatype_handle_at(idx1); let module_handle = context.resolver.module_handle_at(struct_handle.module); let module_id = context.resolver.module_id_for_handle(module_handle); let struct_name = context.resolver.identifier_at(struct_handle.name); // grab ModuleId and struct name for the definition - let def_struct_handle = def_module.struct_handle_at(idx2); + let def_struct_handle = def_module.datatype_handle_at(idx2); let def_module_handle = def_module.module_handle_at(def_struct_handle.module); let def_module_id = def_module.module_id_for_handle(def_module_handle); let def_struct_name = def_module.identifier_at(def_struct_handle.name); diff --git a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/instantiation_loops.rs b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/instantiation_loops.rs index 2fa40c07e10df..81bba7b0a4cbe 100644 --- a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/instantiation_loops.rs +++ b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/instantiation_loops.rs @@ -14,7 +14,6 @@ //! terminate eventually. use move_binary_format::{ - errors::{Location, PartialVMError, PartialVMResult, VMResult}, file_format::{ Bytecode, CompiledModule, FunctionDefinition, FunctionDefinitionIndex, FunctionHandleIndex, @@ -143,13 +142,13 @@ impl<'a> InstantiationLoopChecker<'a> { fn rec(type_params: &mut HashSet, ty: &SignatureToken) { match ty { - Bool | Address | U8 | U16 | U32 | U64 | U128 | U256 | Signer | Struct(_) => (), + Bool | Address | U8 | U16 | U32 | U64 | U128 | U256 | Signer | Datatype(_) => (), TypeParameter(idx) => { type_params.insert(*idx); } Vector(ty) => rec(type_params, ty), Reference(ty) | MutableReference(ty) => rec(type_params, ty), - StructInstantiation(s) => { + DatatypeInstantiation(s) => { let (_, tys) = &**s; for ty in tys { rec(type_params, ty); diff --git a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/instruction_consistency.rs b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/instruction_consistency.rs index fc33c803f10e8..235d6a55eb1dc 100644 --- a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/instruction_consistency.rs +++ b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/instruction_consistency.rs @@ -135,6 +135,21 @@ impl<'a> InstructionConsistency<'a> { | Or | And | Not | Eq | Neq | Lt | Gt | Le | Ge | CopyLoc(_) | MoveLoc(_) | StLoc(_) | MutBorrowLoc(_) | ImmBorrowLoc(_) | VecLen(_) | VecImmBorrow(_) | VecMutBorrow(_) | VecPushBack(_) | VecPopBack(_) | VecSwap(_) | Abort | Nop => (), + PackVariant(_) + | PackVariantGeneric(_) + | UnpackVariant(_) + | UnpackVariantGeneric(_) + | UnpackVariantImmRef(_) + | UnpackVariantGenericImmRef(_) + | UnpackVariantMutRef(_) + | UnpackVariantGenericMutRef(_) + | VariantSwitch(_) => { + return Err( + PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) + .at_code_offset(self.current_function(), offset as CodeOffset) + .with_message("Unexpected variant opcode in version 0".to_string()), + ); + } } } Ok(()) @@ -167,7 +182,7 @@ impl<'a> InstructionConsistency<'a> { generic: bool, ) -> PartialVMResult<()> { let struct_def = self.resolver.struct_def_at(struct_def_index); - let struct_handle = self.resolver.struct_handle_at(struct_def.struct_handle); + let struct_handle = self.resolver.datatype_handle_at(struct_def.struct_handle); if struct_handle.type_parameters.is_empty() == generic { return Err( PartialVMError::new(StatusCode::GENERIC_MEMBER_OPCODE_MISMATCH) diff --git a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/limits.rs b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/limits.rs index 90e92c8d7cd0f..312ff030b89d6 100644 --- a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/limits.rs +++ b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/limits.rs @@ -26,18 +26,18 @@ impl<'a> LimitsVerifier<'a> { let limit_check = Self { resolver: module }; limit_check.verify_constants(config)?; limit_check.verify_function_handles(config)?; - limit_check.verify_struct_handles(config)?; + limit_check.verify_datatype_handles(config)?; limit_check.verify_type_nodes(config)?; limit_check.verify_identifiers(config)?; limit_check.verify_definitions(config) } - fn verify_struct_handles(&self, config: &VerifierConfig) -> PartialVMResult<()> { + fn verify_datatype_handles(&self, config: &VerifierConfig) -> PartialVMResult<()> { if let Some(limit) = config.max_generic_instantiation_length { - for (idx, struct_handle) in self.resolver.struct_handles().iter().enumerate() { + for (idx, struct_handle) in self.resolver.datatype_handles().iter().enumerate() { if struct_handle.type_parameters.len() > limit { return Err(PartialVMError::new(StatusCode::TOO_MANY_TYPE_PARAMETERS) - .at_index(IndexKind::StructHandle, idx as u16)); + .at_index(IndexKind::DatatypeHandle, idx as u16)); } } } @@ -105,7 +105,7 @@ impl<'a> LimitsVerifier<'a> { // Notice that the preorder traversal will iterate all type instantiations, so we // why we can ignore them below. match t { - SignatureToken::Struct(..) | SignatureToken::StructInstantiation(..) => { + SignatureToken::Datatype(..) | SignatureToken::DatatypeInstantiation(..) => { size += STRUCT_SIZE_WEIGHT } SignatureToken::TypeParameter(..) => size += PARAM_SIZE_WEIGHT, @@ -132,7 +132,7 @@ impl<'a> LimitsVerifier<'a> { } let defs = self.resolver.struct_defs(); { - if let Some(max_struct_definitions) = config.max_struct_definitions { + if let Some(max_struct_definitions) = config.max_data_definitions { if defs.len() > max_struct_definitions { return Err(PartialVMError::new( StatusCode::MAX_STRUCT_DEFINITIONS_REACHED, diff --git a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/locals_safety/mod.rs b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/locals_safety/mod.rs index 1ffb24ed80074..13ff8d3993fb8 100644 --- a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/locals_safety/mod.rs +++ b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/locals_safety/mod.rs @@ -160,6 +160,20 @@ fn execute_inner( | Bytecode::VecPopBack(_) | Bytecode::VecUnpack(..) | Bytecode::VecSwap(_) => (), + Bytecode::PackVariant(_) + | Bytecode::PackVariantGeneric(_) + | Bytecode::UnpackVariant(_) + | Bytecode::UnpackVariantGeneric(_) + | Bytecode::UnpackVariantImmRef(_) + | Bytecode::UnpackVariantGenericImmRef(_) + | Bytecode::UnpackVariantMutRef(_) + | Bytecode::UnpackVariantGenericMutRef(_) + | Bytecode::VariantSwitch(_) => { + return Err( + PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) + .with_message("Unexpected variant opcode in version 0".to_string()), + ); + } }; Ok(()) } diff --git a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/reference_safety/abstract_state.rs b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/reference_safety/abstract_state.rs index 66451e2146025..d8d7b9f00a9a9 100644 --- a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/reference_safety/abstract_state.rs +++ b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/reference_safety/abstract_state.rs @@ -440,7 +440,7 @@ impl AbstractState { if is_mut_borrow_with_full_borrows() || is_imm_borrow_with_mut_borrows() { // TODO improve error for mutable case - return Err(self.error(StatusCode::BORROWFIELD_EXISTS_MUTABLE_BORROW_ERROR, offset)); + return Err(self.error(StatusCode::FIELD_EXISTS_MUTABLE_BORROW_ERROR, offset)); } let field_borrow_id = self.new_ref(mut_); diff --git a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/reference_safety/mod.rs b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/reference_safety/mod.rs index 1f52c07f90d50..266daf94cecd6 100644 --- a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/reference_safety/mod.rs +++ b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/reference_safety/mod.rs @@ -425,6 +425,20 @@ fn execute_inner( let vec_ref = safe_unwrap_err!(verifier.stack.pop()); state.vector_op(offset, vec_ref, true)?; } + Bytecode::PackVariant(_) + | Bytecode::PackVariantGeneric(_) + | Bytecode::UnpackVariant(_) + | Bytecode::UnpackVariantGeneric(_) + | Bytecode::UnpackVariantImmRef(_) + | Bytecode::UnpackVariantGenericImmRef(_) + | Bytecode::UnpackVariantMutRef(_) + | Bytecode::UnpackVariantGenericMutRef(_) + | Bytecode::VariantSwitch(_) => { + return Err( + PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) + .with_message("Unexpected variant opcode in version 0".to_string()), + ); + } }; Ok(()) } diff --git a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/regression_tests/reference_analysis.rs b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/regression_tests/reference_analysis.rs index 2df2c7b43a5ed..51bd7d47db5c9 100644 --- a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/regression_tests/reference_analysis.rs +++ b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/regression_tests/reference_analysis.rs @@ -5,12 +5,11 @@ use move_binary_format::{ file_format::{ empty_module, AbilitySet, AddressIdentifierIndex, Bytecode::{self, *}, - CodeUnit, Constant, FieldDefinition, FunctionDefinition, FunctionHandle, - FunctionHandleIndex, IdentifierIndex, ModuleHandle, ModuleHandleIndex, Signature, - SignatureIndex, + CodeUnit, Constant, DatatypeHandle, DatatypeHandleIndex, FieldDefinition, + FunctionDefinition, FunctionHandle, FunctionHandleIndex, IdentifierIndex, ModuleHandle, + ModuleHandleIndex, Signature, SignatureIndex, SignatureToken::{self, *}, - StructDefinition, StructDefinitionIndex, StructFieldInformation, StructHandle, - StructHandleIndex, TypeSignature, Visibility, + StructDefinition, StructDefinitionIndex, StructFieldInformation, TypeSignature, Visibility, Visibility::*, }, CompiledModule, @@ -26,7 +25,7 @@ fn unbalanced_stack_crash() { let mut module = empty_module(); module.version = 5; - module.struct_handles.push(StructHandle { + module.datatype_handles.push(DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(1), abilities: AbilitySet::ALL, @@ -67,7 +66,7 @@ fn unbalanced_stack_crash() { }); module.struct_defs.push(StructDefinition { - struct_handle: StructHandleIndex(0), + struct_handle: DatatypeHandleIndex(0), field_information: StructFieldInformation::Declared(vec![FieldDefinition { name: IdentifierIndex::new(3), signature: TypeSignature(Address), @@ -92,6 +91,7 @@ fn unbalanced_stack_crash() { Ret, ], locals: SignatureIndex::new(2), + jump_tables: vec![], }; let fun_def = FunctionDefinition { code: Some(code_unit), @@ -125,7 +125,7 @@ fn too_many_locals() { address: AddressIdentifierIndex(0), name: IdentifierIndex(0), }], - struct_handles: vec![], + datatype_handles: vec![], function_handles: vec![FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), @@ -152,8 +152,13 @@ fn too_many_locals() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![CopyLoc(2), StLoc(33), Branch(0)], + jump_tables: vec![], }), }], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; let res = crate::verify_module_unmetered(&module); @@ -173,7 +178,7 @@ fn borrow_graph() { address: AddressIdentifierIndex(0), name: IdentifierIndex(0), }], - struct_handles: vec![], + datatype_handles: vec![], function_handles: vec![FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), @@ -203,8 +208,13 @@ fn borrow_graph() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![MoveLoc(0), MoveLoc(1), StLoc(0), StLoc(1), Branch(0)], + jump_tables: vec![], }), }], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; let res = crate::verify_module_unmetered(&module); @@ -269,7 +279,7 @@ fn indirect_code() { address: AddressIdentifierIndex(0), name: IdentifierIndex(0), }], - struct_handles: vec![], + datatype_handles: vec![], function_handles: vec![FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), @@ -307,8 +317,13 @@ fn indirect_code() { code: Some(CodeUnit { locals: SignatureIndex(1), code, + jump_tables: vec![], }), }], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; let res = crate::verify_module_with_config_unmetered(&VerifierConfig::default(), &module) diff --git a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/signature.rs b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/signature.rs index ad881affc24e6..b41af4aba7bf0 100644 --- a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/signature.rs +++ b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/signature.rs @@ -8,9 +8,9 @@ use move_binary_format::{ errors::{Location, PartialVMError, PartialVMResult, VMResult}, file_format::{ - AbilitySet, Bytecode, CodeUnit, CompiledModule, FunctionDefinition, FunctionHandle, - Signature, SignatureIndex, SignatureToken, StructDefinition, StructFieldInformation, - StructTypeParameter, TableIndex, + AbilitySet, Bytecode, CodeUnit, CompiledModule, DatatypeTyParameter, FunctionDefinition, + FunctionHandle, Signature, SignatureIndex, SignatureToken, StructDefinition, + StructFieldInformation, TableIndex, }, file_format_common::VERSION_6, IndexKind, @@ -70,7 +70,7 @@ impl<'a> SignatureChecker<'a> { StructFieldInformation::Native => continue, StructFieldInformation::Declared(fields) => fields, }; - let struct_handle = self.resolver.struct_handle_at(struct_def.struct_handle); + let struct_handle = self.resolver.datatype_handle_at(struct_def.struct_handle); let err_handler = |err: PartialVMError, idx| { err.at_index(IndexKind::FieldDefinition, idx as TableIndex) .at_index(IndexKind::StructDefinition, struct_def_idx as TableIndex) @@ -139,7 +139,7 @@ impl<'a> SignatureChecker<'a> { | MutBorrowGlobalGenericDeprecated(idx) => { let struct_inst = self.resolver.struct_instantiation_at(*idx); let struct_def = self.resolver.struct_def_at(struct_inst.def); - let struct_handle = self.resolver.struct_handle_at(struct_def.struct_handle); + let struct_handle = self.resolver.datatype_handle_at(struct_def.struct_handle); let type_arguments = &self.resolver.signature_at(struct_inst.type_parameters).0; self.check_signature_tokens(type_arguments)?; self.check_generic_instance( @@ -152,7 +152,7 @@ impl<'a> SignatureChecker<'a> { let field_inst = self.resolver.field_instantiation_at(*idx); let field_handle = self.resolver.field_handle_at(field_inst.handle); let struct_def = self.resolver.struct_def_at(field_handle.owner); - let struct_handle = self.resolver.struct_handle_at(struct_def.struct_handle); + let struct_handle = self.resolver.datatype_handle_at(struct_def.struct_handle); let type_arguments = &self.resolver.signature_at(field_inst.type_parameters).0; self.check_signature_tokens(type_arguments)?; self.check_generic_instance( @@ -243,6 +243,20 @@ impl<'a> SignatureChecker<'a> { | MoveFromDeprecated(_) | Abort | Nop => Ok(()), + PackVariant(_) + | PackVariantGeneric(_) + | UnpackVariant(_) + | UnpackVariantGeneric(_) + | UnpackVariantImmRef(_) + | UnpackVariantGenericImmRef(_) + | UnpackVariantMutRef(_) + | UnpackVariantGenericMutRef(_) + | VariantSwitch(_) => { + return Err( + PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) + .with_message("Unexpected variant opcode in version 0".to_string()), + ); + } }; result.map_err(|err| { err.append_message_with_separator(' ', format!("at offset {} ", offset)) @@ -256,13 +270,13 @@ impl<'a> SignatureChecker<'a> { &self, ty: &SignatureToken, is_phantom_pos: bool, - type_parameters: &[StructTypeParameter], + type_parameters: &[DatatypeTyParameter], ) -> PartialVMResult<()> { match ty { SignatureToken::Vector(ty) => self.check_phantom_params(ty, false, type_parameters)?, - SignatureToken::StructInstantiation(s) => { + SignatureToken::DatatypeInstantiation(s) => { let (idx, type_arguments) = &**s; - let sh = self.resolver.struct_handle_at(*idx); + let sh = self.resolver.datatype_handle_at(*idx); for (i, ty) in type_arguments.iter().enumerate() { self.check_phantom_params( ty, @@ -282,7 +296,7 @@ impl<'a> SignatureChecker<'a> { } } - SignatureToken::Struct(_) + SignatureToken::Datatype(_) | SignatureToken::Reference(_) | SignatureToken::MutableReference(_) | SignatureToken::Bool @@ -326,7 +340,7 @@ impl<'a> SignatureChecker<'a> { fn check_signature_token(&self, ty: &SignatureToken) -> PartialVMResult<()> { use SignatureToken::*; match ty { - U8 | U16 | U32 | U64 | U128 | U256 | Bool | Address | Signer | Struct(_) + U8 | U16 | U32 | U64 | U128 | U256 | Bool | Address | Signer | Datatype(_) | TypeParameter(_) => Ok(()), Reference(_) | MutableReference(_) => { // TODO: Prop tests expect us to NOT check the inner types. @@ -335,7 +349,7 @@ impl<'a> SignatureChecker<'a> { .with_message("reference not allowed".to_string())) } Vector(ty) => self.check_signature_token(ty), - StructInstantiation(s) => { + DatatypeInstantiation(s) => { let (_, type_arguments) = &**s; self.check_signature_tokens(type_arguments) } @@ -375,13 +389,13 @@ impl<'a> SignatureChecker<'a> { type_parameters: &[AbilitySet], ) -> PartialVMResult<()> { match s { - SignatureToken::StructInstantiation(s) => { + SignatureToken::DatatypeInstantiation(s) => { let (idx, type_arguments) = &**s; // Check that the instantiation satisfies the `idx` struct's constraints // Cannot be checked completely if we do not know the constraints of type parameters // i.e. it cannot be checked unless we are inside some module member. The only case // where that happens is when checking the signature pool itself - let sh = self.resolver.struct_handle_at(*idx); + let sh = self.resolver.datatype_handle_at(*idx); self.check_generic_instance( type_arguments, sh.type_param_constraints(), @@ -392,7 +406,7 @@ impl<'a> SignatureChecker<'a> { | SignatureToken::MutableReference(_) | SignatureToken::Vector(_) | SignatureToken::TypeParameter(_) - | SignatureToken::Struct(_) + | SignatureToken::Datatype(_) | SignatureToken::Bool | SignatureToken::U8 | SignatureToken::U16 diff --git a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/stack_usage_verifier.rs b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/stack_usage_verifier.rs index 1c3ee7db190f9..8142c35ff69d1 100644 --- a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/stack_usage_verifier.rs +++ b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/stack_usage_verifier.rs @@ -265,6 +265,20 @@ impl<'a> StackUsageVerifier<'a> { }; (1, field_count as u64) } + Bytecode::PackVariant(_) + | Bytecode::PackVariantGeneric(_) + | Bytecode::UnpackVariant(_) + | Bytecode::UnpackVariantGeneric(_) + | Bytecode::UnpackVariantImmRef(_) + | Bytecode::UnpackVariantGenericImmRef(_) + | Bytecode::UnpackVariantMutRef(_) + | Bytecode::UnpackVariantGenericMutRef(_) + | Bytecode::VariantSwitch(_) => { + return Err( + PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) + .with_message("Unexpected variant opcode in version 0".to_string()), + ); + } }) } diff --git a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/struct_defs.rs b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/struct_defs.rs index 30e28762dc056..96c09a87e341c 100644 --- a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/struct_defs.rs +++ b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/struct_defs.rs @@ -8,7 +8,7 @@ use move_binary_format::{ errors::{verification_error, Location, PartialVMError, PartialVMResult, VMResult}, file_format::{ - CompiledModule, SignatureToken, StructDefinitionIndex, StructHandleIndex, TableIndex, + CompiledModule, DatatypeHandleIndex, SignatureToken, StructDefinitionIndex, TableIndex, }, internals::ModuleIndex, IndexKind, @@ -35,7 +35,7 @@ impl<'a> RecursiveStructDefChecker<'a> { match toposort(&graph, None) { Ok(_) => Ok(()), Err(cycle) => Err(verification_error( - StatusCode::RECURSIVE_STRUCT_DEFINITION, + StatusCode::RECURSIVE_DATATYPE_DEFINITION, IndexKind::StructDefinition, cycle.node_id().into_index() as TableIndex, )), @@ -48,7 +48,7 @@ impl<'a> RecursiveStructDefChecker<'a> { struct StructDefGraphBuilder<'a> { module: &'a CompiledModule, /// Used to follow field definitions' signatures' struct handles to their struct definitions. - handle_to_def: BTreeMap, + handle_to_def: BTreeMap, } impl<'a> StructDefGraphBuilder<'a> { @@ -119,7 +119,7 @@ impl<'a> StructDefGraphBuilder<'a> { ) } T::Vector(inner) => self.add_signature_token(neighbors, cur_idx, inner)?, - T::Struct(sh_idx) => { + T::Datatype(sh_idx) => { if let Some(struct_def_idx) = self.handle_to_def.get(sh_idx) { neighbors .entry(cur_idx) @@ -127,7 +127,7 @@ impl<'a> StructDefGraphBuilder<'a> { .insert(*struct_def_idx); } } - T::StructInstantiation(s) => { + T::DatatypeInstantiation(s) => { let (sh_idx, inners) = &**s; if let Some(struct_def_idx) = self.handle_to_def.get(sh_idx) { neighbors diff --git a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/type_safety.rs b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/type_safety.rs index ebf578e6a936c..394ae6034ef46 100644 --- a/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/type_safety.rs +++ b/external-crates/move/move-execution/v0/crates/move-bytecode-verifier/src/type_safety.rs @@ -13,10 +13,9 @@ use move_binary_format::{ control_flow_graph::ControlFlowGraph, errors::{PartialVMError, PartialVMResult}, file_format::{ - AbilitySet, Bytecode, CodeOffset, CompiledModule, FieldHandleIndex, + AbilitySet, Bytecode, CodeOffset, CompiledModule, DatatypeHandleIndex, FieldHandleIndex, FunctionDefinitionIndex, FunctionHandle, LocalIndex, Signature, SignatureToken, SignatureToken as ST, StructDefinition, StructDefinitionIndex, StructFieldInformation, - StructHandleIndex, }, safe_unwrap_err, }; @@ -940,6 +939,20 @@ fn verify_instr( } verifier.push(meter, ST::U256)?; } + Bytecode::PackVariant(_) + | Bytecode::PackVariantGeneric(_) + | Bytecode::UnpackVariant(_) + | Bytecode::UnpackVariantGeneric(_) + | Bytecode::UnpackVariantImmRef(_) + | Bytecode::UnpackVariantGenericImmRef(_) + | Bytecode::UnpackVariantMutRef(_) + | Bytecode::UnpackVariantGenericMutRef(_) + | Bytecode::VariantSwitch(_) => { + return Err( + PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) + .with_message("Unexpected variant opcode in version 0".to_string()), + ); + } }; Ok(()) } @@ -948,11 +961,11 @@ fn verify_instr( // Helpers functions for types // -fn materialize_type(struct_handle: StructHandleIndex, type_args: &Signature) -> SignatureToken { +fn materialize_type(struct_handle: DatatypeHandleIndex, type_args: &Signature) -> SignatureToken { if type_args.is_empty() { - ST::Struct(struct_handle) + ST::Datatype(struct_handle) } else { - ST::StructInstantiation(Box::new((struct_handle, type_args.0.clone()))) + ST::DatatypeInstantiation(Box::new((struct_handle, type_args.0.clone()))) } } @@ -974,10 +987,10 @@ fn instantiate(token: &SignatureToken, subst: &Signature) -> SignatureToken { Address => Address, Signer => Signer, Vector(ty) => Vector(Box::new(instantiate(ty, subst))), - Struct(idx) => Struct(*idx), - StructInstantiation(s) => { + Datatype(idx) => Datatype(*idx), + DatatypeInstantiation(s) => { let (idx, struct_type_args) = &**s; - StructInstantiation(Box::new(( + DatatypeInstantiation(Box::new(( *idx, struct_type_args .iter() diff --git a/external-crates/move/move-execution/v0/crates/move-vm-runtime/src/interpreter.rs b/external-crates/move/move-execution/v0/crates/move-vm-runtime/src/interpreter.rs index b88972fd4d4a1..38db71a81dddc 100644 --- a/external-crates/move/move-execution/v0/crates/move-vm-runtime/src/interpreter.rs +++ b/external-crates/move/move-execution/v0/crates/move-vm-runtime/src/interpreter.rs @@ -1268,6 +1268,15 @@ impl Frame { gas_meter.charge_vec_swap(make_ty!(ty))?; vec_ref.swap(idx1, idx2, ty)?; } + Bytecode::PackVariant(_) + | Bytecode::PackVariantGeneric(_) + | Bytecode::UnpackVariant(_) + | Bytecode::UnpackVariantGeneric(_) + | Bytecode::UnpackVariantImmRef(_) + | Bytecode::UnpackVariantMutRef(_) + | Bytecode::UnpackVariantGenericImmRef(_) + | Bytecode::UnpackVariantGenericMutRef(_) + | Bytecode::VariantSwitch(_) => unreachable!("enums not supported in v0"), } Ok(InstrRet::Ok) @@ -1397,7 +1406,7 @@ impl Frame { Type::Reference(ty) | Type::MutableReference(ty) | Type::Vector(ty) => { Self::check_depth_of_type_impl(resolver, ty, check_depth!(1), max_depth)? } - Type::Struct(si) => { + Type::Datatype(si) => { let struct_type = resolver.loader().get_struct_type(*si).ok_or_else(|| { PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) .with_message("Struct Definition not resolved".to_string()) @@ -1408,7 +1417,7 @@ impl Frame { .ok_or_else(|| { PartialVMError::new(StatusCode::VM_MAX_VALUE_DEPTH_REACHED) })? .solve(&[])?) } - Type::StructInstantiation(struct_inst) => { + Type::DatatypeInstantiation(struct_inst) => { let (si, ty_args) = &**struct_inst; // Calculate depth of all type arguments, and make sure they themselves are not too deep. let ty_arg_depths = ty_args diff --git a/external-crates/move/move-execution/v0/crates/move-vm-runtime/src/loader.rs b/external-crates/move/move-execution/v0/crates/move-vm-runtime/src/loader.rs index a117e9f8ad4ed..80c0d72bceaa5 100644 --- a/external-crates/move/move-execution/v0/crates/move-vm-runtime/src/loader.rs +++ b/external-crates/move/move-execution/v0/crates/move-vm-runtime/src/loader.rs @@ -32,7 +32,9 @@ use move_core_types::{ use move_vm_config::runtime::VMConfig; use move_vm_types::{ data_store::DataStore, - loaded_data::runtime_types::{CachedStructIndex, DepthFormula, StructType, Type}, + loaded_data::runtime_types::{ + CachedDatatype, CachedTypeIndex, Datatype, DepthFormula, StructType, Type, + }, }; use parking_lot::RwLock; use std::{ @@ -107,7 +109,7 @@ pub struct ModuleCache { loaded_modules: BinaryCache<(AccountAddress, ModuleId), LoadedModule>, /// Global cache of loaded structs, shared among all modules. - structs: BinaryCache<(ModuleId, Identifier), StructType>, + structs: BinaryCache<(ModuleId, Identifier), CachedDatatype>, /// Global list of loaded functions, shared among all modules. functions: Vec>, } @@ -158,7 +160,7 @@ impl ModuleCache { } // Retrieve a struct by index - fn struct_at(&self, idx: CachedStructIndex) -> Arc { + fn struct_at(&self, idx: CachedTypeIndex) -> Arc { Arc::clone(&self.structs.binaries[idx.0]) } @@ -221,7 +223,7 @@ impl ModuleCache { // Add new structs and collect their field signatures let mut field_signatures = vec![]; for (idx, struct_def) in module.struct_defs().iter().enumerate() { - let struct_handle = module.struct_handle_at(struct_def.struct_handle); + let struct_handle = module.datatype_handle_at(struct_def.struct_handle); let name = module.identifier_at(struct_handle.name); let struct_key = (runtime_id.clone(), name.to_owned()); @@ -241,16 +243,18 @@ impl ModuleCache { self.structs.insert( struct_key, - StructType { - fields: vec![], - field_names, + CachedDatatype { abilities: struct_handle.abilities, type_parameters: struct_handle.type_parameters.clone(), name: name.to_owned(), defining_id, runtime_id: runtime_id.clone(), - struct_def: StructDefinitionIndex(idx as u16), depth: None, + datatype_info: Datatype::Struct(StructType { + fields: vec![], + field_names, + struct_def: StructDefinitionIndex(idx as u16), + }), }, )?; @@ -283,7 +287,14 @@ impl ModuleCache { .zip(self.structs.binaries.iter_mut().rev()) { match Arc::get_mut(struct_type) { - Some(struct_type) => struct_type.fields = fields, + Some(ref mut x) => match &mut x.datatype_info { + Datatype::Enum(_) => { + unreachable!("enum types cannot be loaded into the cache in v0") + } + Datatype::Struct(ref mut struct_type) => { + struct_type.fields = fields; + } + }, None => { // we have pending references to the `Arc` which is impossible, // given the code that adds the `Arc` is above and no reference to @@ -292,8 +303,16 @@ impl ModuleCache { // over and log the issue. error!("Arc cannot have any live reference while publishing"); let mut struct_copy = (**struct_type).clone(); - struct_copy.fields = fields; - *struct_type = Arc::new(struct_copy); + match struct_copy.datatype_info { + Datatype::Enum(_) => { + unreachable!("enum types cannot be loaded into the cache in v0") + } + Datatype::Struct(ref mut s_info) => { + s_info.fields = fields; + struct_copy.datatype_info = Datatype::Struct(s_info.clone()); + *struct_type = Arc::new(struct_copy); + } + } } } } @@ -370,8 +389,8 @@ impl ModuleCache { SignatureToken::MutableReference(inner_tok) => { Type::MutableReference(Box::new(self.make_type(module, inner_tok)?)) } - SignatureToken::Struct(sh_idx) => { - let struct_handle = module.struct_handle_at(*sh_idx); + SignatureToken::Datatype(sh_idx) => { + let struct_handle = module.datatype_handle_at(*sh_idx); let struct_name = module.identifier_at(struct_handle.name); let module_handle = module.module_handle_at(struct_handle.module); let runtime_id = ModuleId::new( @@ -379,15 +398,15 @@ impl ModuleCache { module.identifier_at(module_handle.name).to_owned(), ); let def_idx = self.resolve_struct_by_name(struct_name, &runtime_id)?.0; - Type::Struct(def_idx) + Type::Datatype(def_idx) } - SignatureToken::StructInstantiation(struct_inst) => { + SignatureToken::DatatypeInstantiation(struct_inst) => { let (sh_idx, tys) = &**struct_inst; let type_parameters: Vec<_> = tys .iter() .map(|tok| self.make_type(module, tok)) .collect::>()?; - let struct_handle = module.struct_handle_at(*sh_idx); + let struct_handle = module.datatype_handle_at(*sh_idx); let struct_name = module.identifier_at(struct_handle.name); let module_handle = module.module_handle_at(struct_handle.module); let runtime_id = ModuleId::new( @@ -395,7 +414,7 @@ impl ModuleCache { module.identifier_at(module_handle.name).to_owned(), ); let def_idx = self.resolve_struct_by_name(struct_name, &runtime_id)?.0; - Type::StructInstantiation(Box::new((def_idx, type_parameters))) + Type::DatatypeInstantiation(Box::new((def_idx, type_parameters))) } }; Ok(res) @@ -403,8 +422,8 @@ impl ModuleCache { fn calculate_depth_of_struct( &self, - struct_type: &StructType, - depth_cache: &mut BTreeMap, + struct_type: &CachedDatatype, + depth_cache: &mut BTreeMap, ) -> PartialVMResult { let def_idx = self .resolve_struct_by_name(&struct_type.name, &struct_type.runtime_id)? @@ -418,11 +437,14 @@ impl ModuleCache { return Ok(form.clone()); } - let formulas = struct_type - .fields - .iter() - .map(|field_type| self.calculate_depth_of_type(field_type, depth_cache)) - .collect::>>()?; + let formulas = match &struct_type.datatype_info { + Datatype::Enum(_) => unreachable!("enum types cannot be loaded into the cache in v0"), + Datatype::Struct(s_info) => s_info + .fields + .iter() + .map(|field_type| self.calculate_depth_of_type(field_type, depth_cache)) + .collect::>>()?, + }; let mut formula = DepthFormula::normalize(formulas); // add 1 for the struct itself formula.add(1); @@ -439,7 +461,7 @@ impl ModuleCache { fn calculate_depth_of_type( &self, ty: &Type, - depth_cache: &mut BTreeMap, + depth_cache: &mut BTreeMap, ) -> PartialVMResult { Ok(match ty { Type::Bool @@ -459,13 +481,13 @@ impl ModuleCache { inner } Type::TyParam(ty_idx) => DepthFormula::type_parameter(*ty_idx), - Type::Struct(cache_idx) => { + Type::Datatype(cache_idx) => { let struct_type = self.struct_at(*cache_idx); let struct_formula = self.calculate_depth_of_struct(&struct_type, depth_cache)?; debug_assert!(struct_formula.terms.is_empty()); struct_formula } - Type::StructInstantiation(struct_inst) => { + Type::DatatypeInstantiation(struct_inst) => { let (cache_idx, ty_args) = &**struct_inst; let struct_type = self.struct_at(*cache_idx); let ty_arg_map = ty_args @@ -488,12 +510,12 @@ impl ModuleCache { &self, struct_name: &IdentStr, runtime_id: &ModuleId, - ) -> PartialVMResult<(CachedStructIndex, Arc)> { + ) -> PartialVMResult<(CachedTypeIndex, Arc)> { match self .structs .get_with_idx(&(runtime_id.clone(), struct_name.to_owned())) { - Some((idx, struct_)) => Ok((CachedStructIndex(idx), Arc::clone(struct_))), + Some((idx, struct_)) => Ok((CachedTypeIndex(idx), Arc::clone(struct_))), None => Err(PartialVMError::new(StatusCode::TYPE_RESOLUTION_FAILURE) .with_message(format!("Cannot find {runtime_id}::{struct_name} in cache",))), } @@ -801,7 +823,7 @@ impl Loader { name: &IdentStr, runtime_id: &ModuleId, data_store: &impl DataStore, - ) -> VMResult<(CachedStructIndex, Arc)> { + ) -> VMResult<(CachedTypeIndex, Arc)> { self.load_module(runtime_id, data_store)?; self.module_cache .read() @@ -831,7 +853,7 @@ impl Loader { let (idx, struct_type) = self.load_struct_by_name(&struct_tag.name, &runtime_id, data_store)?; if struct_type.type_parameters.is_empty() && struct_tag.type_params.is_empty() { - Type::Struct(idx) + Type::Datatype(idx) } else { let mut type_params = vec![]; for ty_param in &struct_tag.type_params { @@ -839,7 +861,7 @@ impl Loader { } self.verify_ty_args(struct_type.type_param_constraints(), &type_params) .map_err(|e| e.finish(Location::Undefined))?; - Type::StructInstantiation(Box::new((idx, type_params))) + Type::DatatypeInstantiation(Box::new((idx, type_params))) } } }) @@ -1119,7 +1141,7 @@ impl Loader { // existing type instantiation. // If that number is larger than MAX_TYPE_INSTANTIATION_NODES, refuse to construct this type. // This prevents constructing larger and lager types via struct instantiation. - if let Type::StructInstantiation(box_struct_inst) = ty { + if let Type::DatatypeInstantiation(box_struct_inst) = ty { let (_, struct_inst) = &**box_struct_inst; let mut sum_nodes = 1u64; for ty in ty_args.iter().chain(struct_inst.iter()) { @@ -1177,7 +1199,7 @@ impl Loader { (compiled, loaded) } - pub(crate) fn get_struct_type(&self, idx: CachedStructIndex) -> Option> { + pub(crate) fn get_struct_type(&self, idx: CachedTypeIndex) -> Option> { self.module_cache .read() .structs @@ -1210,8 +1232,8 @@ impl Loader { vec![false], vec![self.abilities(ty)?], ), - Type::Struct(idx) => Ok(self.module_cache.read().struct_at(*idx).abilities), - Type::StructInstantiation(struct_inst) => { + Type::Datatype(idx) => Ok(self.module_cache.read().struct_at(*idx).abilities), + Type::DatatypeInstantiation(struct_inst) => { let (idx, type_args) = &**struct_inst; let struct_type = self.module_cache.read().struct_at(*idx); let declared_phantom_parameters = struct_type @@ -1333,7 +1355,7 @@ impl<'a> Resolver<'a> { let struct_def = match &self.binary { BinaryType::Module { loaded, .. } => loaded.struct_at(idx), }; - Type::Struct(struct_def) + Type::Datatype(struct_def) } pub(crate) fn instantiate_generic_type( @@ -1357,7 +1379,7 @@ impl<'a> Resolver<'a> { } } - Ok(Type::StructInstantiation(Box::new(( + Ok(Type::DatatypeInstantiation(Box::new(( struct_inst.def, struct_inst .instantiation @@ -1453,7 +1475,7 @@ pub(crate) struct LoadedModule { // the instruction carries an index into this table which contains the index into the // glabal table of types. No instantiation of generic types is saved into the global table. #[allow(dead_code)] - struct_refs: Vec, + struct_refs: Vec, structs: Vec, // materialized instantiations, whether partial or not struct_instantiations: Vec, @@ -1503,7 +1525,7 @@ impl LoadedModule { let mut function_map = HashMap::new(); let mut single_signature_token_map = BTreeMap::new(); - for struct_handle in module.struct_handles() { + for struct_handle in module.datatype_handles() { let struct_name = module.identifier_at(struct_handle.name); let module_handle = module.module_handle_at(struct_handle.module); let runtime_id = module.module_id_for_handle(module_handle); @@ -1512,7 +1534,11 @@ impl LoadedModule { for struct_def in module.struct_defs() { let idx = struct_refs[struct_def.struct_handle.0 as usize]; - let field_count = cache.structs.binaries[idx.0].fields.len() as u16; + let field_count = cache.structs.binaries[idx.0] + .get_struct() + .expect("enums cannot exist in v0") + .fields + .len() as u16; structs.push(StructDef { field_count, idx }); } @@ -1643,7 +1669,7 @@ impl LoadedModule { }) } - fn struct_at(&self, idx: StructDefinitionIndex) -> CachedStructIndex { + fn struct_at(&self, idx: StructDefinitionIndex) -> CachedTypeIndex { self.structs[idx.0 as usize].idx } @@ -1874,7 +1900,7 @@ struct StructDef { // struct field count field_count: u16, // `ModuelCache::structs` global table index - idx: CachedStructIndex, + idx: CachedTypeIndex, } #[derive(Debug)] @@ -1882,7 +1908,7 @@ struct StructInstantiation { // struct field count field_count: u16, // `ModuelCache::structs` global table index. It is the generic type. - def: CachedStructIndex, + def: CachedTypeIndex, instantiation: Vec, } @@ -1891,7 +1917,7 @@ struct StructInstantiation { struct FieldHandle { offset: usize, // `ModuelCache::structs` global table index. It is the generic type. - owner: CachedStructIndex, + owner: CachedTypeIndex, } // A field instantiation. The offset is the only used information when operating on a field @@ -1900,7 +1926,7 @@ struct FieldInstantiation { offset: usize, // `ModuelCache::structs` global table index. It is the generic type. #[allow(unused)] - owner: CachedStructIndex, + owner: CachedTypeIndex, } // @@ -1936,7 +1962,7 @@ impl StructInfo { } pub(crate) struct TypeCache { - structs: HashMap, StructInfo>>, + structs: HashMap, StructInfo>>, } impl TypeCache { @@ -1961,7 +1987,7 @@ const MAX_TYPE_INSTANTIATION_NODES: u64 = 128; impl Loader { fn read_cached_struct_tag( &self, - gidx: CachedStructIndex, + gidx: CachedTypeIndex, ty_args: &[Type], tag_type: StructTagType, ) -> Option { @@ -1977,7 +2003,7 @@ impl Loader { fn struct_gidx_to_type_tag( &self, - gidx: CachedStructIndex, + gidx: CachedTypeIndex, ty_args: &[Type], tag_type: StructTagType, ) -> PartialVMResult { @@ -2044,12 +2070,12 @@ impl Loader { Type::Vector(ty) => { TypeTag::Vector(Box::new(self.type_to_type_tag_impl(ty, tag_type)?)) } - Type::Struct(gidx) => TypeTag::Struct(Box::new(self.struct_gidx_to_type_tag( + Type::Datatype(gidx) => TypeTag::Struct(Box::new(self.struct_gidx_to_type_tag( *gidx, &[], tag_type, )?)), - Type::StructInstantiation(struct_inst) => { + Type::DatatypeInstantiation(struct_inst) => { let (gidx, ty_args) = &**struct_inst; TypeTag::Struct(Box::new( self.struct_gidx_to_type_tag(*gidx, ty_args, tag_type)?, @@ -2073,7 +2099,7 @@ impl Loader { result += 1; todo.push(ty); } - Type::StructInstantiation(struct_inst) => { + Type::DatatypeInstantiation(struct_inst) => { let (_, ty_args) = &**struct_inst; result += 1; todo.extend(ty_args.iter()) @@ -2088,7 +2114,7 @@ impl Loader { fn struct_gidx_to_type_layout( &self, - gidx: CachedStructIndex, + gidx: CachedTypeIndex, ty_args: &[Type], count: &mut u64, depth: u64, @@ -2105,7 +2131,8 @@ impl Loader { } let count_before = *count; - let struct_type = self.module_cache.read().struct_at(gidx); + let binding = self.module_cache.read().struct_at(gidx); + let struct_type = binding.get_struct().expect("enums cannot exist at v0"); let field_tys = struct_type .fields .iter() @@ -2158,13 +2185,13 @@ impl Loader { Type::Vector(ty) => R::MoveTypeLayout::Vector(Box::new( self.type_to_type_layout_impl(ty, count, depth + 1)?, )), - Type::Struct(gidx) => R::MoveTypeLayout::Struct(self.struct_gidx_to_type_layout( + Type::Datatype(gidx) => R::MoveTypeLayout::Struct(self.struct_gidx_to_type_layout( *gidx, &[], count, depth, )?), - Type::StructInstantiation(struct_inst) => { + Type::DatatypeInstantiation(struct_inst) => { let (gidx, ty_args) = &**struct_inst; R::MoveTypeLayout::Struct( self.struct_gidx_to_type_layout(*gidx, ty_args, count, depth)?, @@ -2181,7 +2208,7 @@ impl Loader { fn struct_gidx_to_fully_annotated_layout( &self, - gidx: CachedStructIndex, + gidx: CachedTypeIndex, ty_args: &[Type], count: &mut u64, depth: u64, @@ -2197,7 +2224,8 @@ impl Loader { } } - let struct_type = self.module_cache.read().struct_at(gidx); + let binding = self.module_cache.read().struct_at(gidx); + let struct_type = binding.get_struct().expect("enums cannot exist at v0"); if struct_type.fields.len() != struct_type.field_names.len() { return Err( PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR).with_message( @@ -2260,10 +2288,10 @@ impl Loader { Type::Vector(ty) => A::MoveTypeLayout::Vector(Box::new( self.type_to_fully_annotated_layout_impl(ty, count, depth + 1)?, )), - Type::Struct(gidx) => A::MoveTypeLayout::Struct( + Type::Datatype(gidx) => A::MoveTypeLayout::Struct( self.struct_gidx_to_fully_annotated_layout(*gidx, &[], count, depth)?, ), - Type::StructInstantiation(struct_inst) => { + Type::DatatypeInstantiation(struct_inst) => { let (gidx, ty_args) = &**struct_inst; A::MoveTypeLayout::Struct( self.struct_gidx_to_fully_annotated_layout(*gidx, ty_args, count, depth)?, diff --git a/external-crates/move/move-execution/v0/crates/move-vm-runtime/src/session.rs b/external-crates/move/move-execution/v0/crates/move-vm-runtime/src/session.rs index 58a9cc84555ab..a396c55ba447e 100644 --- a/external-crates/move/move-execution/v0/crates/move-vm-runtime/src/session.rs +++ b/external-crates/move/move-execution/v0/crates/move-vm-runtime/src/session.rs @@ -22,7 +22,7 @@ use move_core_types::{ use move_vm_types::{ data_store::DataStore, gas::GasMeter, - loaded_data::runtime_types::{CachedStructIndex, StructType, Type}, + loaded_data::runtime_types::{CachedDatatype, CachedTypeIndex, Type}, }; use std::{borrow::Borrow, sync::Arc}; @@ -211,7 +211,7 @@ impl<'r, 'l, S: MoveResolver> Session<'r, 'l, S> { &self, module_id: &ModuleId, struct_name: &IdentStr, - ) -> VMResult<(CachedStructIndex, Arc)> { + ) -> VMResult<(CachedTypeIndex, Arc)> { self.runtime .loader() .load_struct_by_name(struct_name, module_id, &self.data_cache) @@ -259,7 +259,7 @@ impl<'r, 'l, S: MoveResolver> Session<'r, 'l, S> { /// Fetch a struct type from cache, if the index is in bounds /// Helpful when paired with load_type, or any other API that returns 'Type' - pub fn get_struct_type(&self, index: CachedStructIndex) -> Option> { + pub fn get_struct_type(&self, index: CachedTypeIndex) -> Option> { self.runtime.loader().get_struct_type(index) } diff --git a/external-crates/move/move-execution/v0/crates/move-vm-runtime/src/unit_tests/vm_arguments_tests.rs b/external-crates/move/move-execution/v0/crates/move-vm-runtime/src/unit_tests/vm_arguments_tests.rs index 8c3297675b176..abf424d8db730 100644 --- a/external-crates/move/move-execution/v0/crates/move-vm-runtime/src/unit_tests/vm_arguments_tests.rs +++ b/external-crates/move/move-execution/v0/crates/move-vm-runtime/src/unit_tests/vm_arguments_tests.rs @@ -9,9 +9,9 @@ use move_binary_format::{ errors::{VMError, VMResult}, file_format::{ empty_module, AbilitySet, AddressIdentifierIndex, Bytecode, CodeUnit, CompiledModule, - FieldDefinition, FunctionDefinition, FunctionHandle, FunctionHandleIndex, IdentifierIndex, - ModuleHandle, ModuleHandleIndex, Signature, SignatureIndex, SignatureToken, - StructDefinition, StructFieldInformation, StructHandle, StructHandleIndex, TableIndex, + DatatypeHandle, DatatypeHandleIndex, FieldDefinition, FunctionDefinition, FunctionHandle, + FunctionHandleIndex, IdentifierIndex, ModuleHandle, ModuleHandleIndex, Signature, + SignatureIndex, SignatureToken, StructDefinition, StructFieldInformation, TableIndex, TypeSignature, Visibility, }, }; @@ -60,7 +60,7 @@ fn make_module_with_function( address: AddressIdentifierIndex(0), name: IdentifierIndex(0), }], - struct_handles: vec![StructHandle { + datatype_handles: vec![DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(1), abilities: AbilitySet::EMPTY, @@ -92,7 +92,7 @@ fn make_module_with_function( metadata: vec![], struct_defs: vec![StructDefinition { - struct_handle: StructHandleIndex(0), + struct_handle: DatatypeHandleIndex(0), field_information: StructFieldInformation::Declared(vec![FieldDefinition { name: IdentifierIndex(1), signature: TypeSignature(SignatureToken::Bool), @@ -106,8 +106,13 @@ fn make_module_with_function( code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::LdU64(0), Bytecode::Abort], + jump_tables: vec![], }), }], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; (module, function_name) } @@ -216,37 +221,37 @@ fn call_script_function( fn deprecated_bad_signatures() -> Vec { vec![ // struct in signature - Signature(vec![SignatureToken::Struct(StructHandleIndex(0))]), + Signature(vec![SignatureToken::Datatype(DatatypeHandleIndex(0))]), // struct in signature Signature(vec![ SignatureToken::Bool, - SignatureToken::Struct(StructHandleIndex(0)), + SignatureToken::Datatype(DatatypeHandleIndex(0)), SignatureToken::U64, ]), // reference to struct in signature Signature(vec![ SignatureToken::Address, - SignatureToken::MutableReference(Box::new(SignatureToken::Struct(StructHandleIndex( - 0, - )))), + SignatureToken::MutableReference(Box::new(SignatureToken::Datatype( + DatatypeHandleIndex(0), + ))), ]), // vector of struct in signature Signature(vec![ SignatureToken::Bool, - SignatureToken::Vector(Box::new(SignatureToken::Struct(StructHandleIndex(0)))), + SignatureToken::Vector(Box::new(SignatureToken::Datatype(DatatypeHandleIndex(0)))), SignatureToken::U64, ]), // vector of vector of struct in signature Signature(vec![ SignatureToken::Bool, SignatureToken::Vector(Box::new(SignatureToken::Vector(Box::new( - SignatureToken::Struct(StructHandleIndex(0)), + SignatureToken::Datatype(DatatypeHandleIndex(0)), )))), SignatureToken::U64, ]), // reference to vector in signature Signature(vec![SignatureToken::Reference(Box::new( - SignatureToken::Vector(Box::new(SignatureToken::Struct(StructHandleIndex(0)))), + SignatureToken::Vector(Box::new(SignatureToken::Datatype(DatatypeHandleIndex(0)))), ))]), // reference to vector in signature Signature(vec![SignatureToken::Reference(Box::new( diff --git a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.proptest-regressions b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.proptest-regressions index 6baf2ee61f189..3945bd370c9d0 100644 --- a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.proptest-regressions +++ b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.proptest-regressions @@ -4,7 +4,7 @@ # # It is recommended to check this file in to source control so that # everyone who runs the test benefits from these saved cases. -cc 2beb0a0e65962432af560e626fa109d269b07db8807968413425f0bb14bb3667 # shrinks to module = CompiledModule: { struct_handles: [ StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } -cc c14ae393a6eefae82c0f4ede2acaa0aa0e993c1bba3fe3e5958e6e31cb5d2957 # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] struct_handles: [ StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = [] -cc 88615e15ef42d29405cd91d6d0a573ccbeb833d0c7471f718ee794bc5ba399ca # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] struct_handles: [ StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 }, StructDefinition { struct_handle: 2, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = [OutOfBoundsMutation { src_kind: StructDefinition, src_idx: Index(0), dst_kind: FieldDefinition, offset: 0 }] -cc a34039f5d57751762a6eacf3ca3a2857781fb0bd0af0b7a06a9427f896f29aa9 # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] struct_handles: [ StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, StructHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x2, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x0, code: CodeUnit { max_stack_size: 0, locals: 0 code: [ BrTrue(1),] } },] type_signatures: [ TypeSignature(Unit), TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = [] +cc 2beb0a0e65962432af560e626fa109d269b07db8807968413425f0bb14bb3667 # shrinks to module = CompiledModule: { datatype_handles: [ DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } +cc c14ae393a6eefae82c0f4ede2acaa0aa0e993c1bba3fe3e5958e6e31cb5d2957 # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] datatype_handles: [ DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = [] +cc 88615e15ef42d29405cd91d6d0a573ccbeb833d0c7471f718ee794bc5ba399ca # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] datatype_handles: [ DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x4, field_count: 0, fields: 0 }, StructDefinition { struct_handle: 2, access: 0x4, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x2, code: CodeUnit { max_stack_size: 0, locals: 0 code: [] } },] type_signatures: [ TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = [OutOfBoundsMutation { src_kind: StructDefinition, src_idx: Index(0), dst_kind: FieldDefinition, offset: 0 }] +cc a34039f5d57751762a6eacf3ca3a2857781fb0bd0af0b7a06a9427f896f29aa9 # shrinks to module = CompiledModule: { module_handles: [ ModuleHandle { address: AddressPoolIndex(0), name: IdentifierIndex(0) },] datatype_handles: [ DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false }, DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), is_resource: false },] function_handles: [ FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(0) }, FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), signature: FunctionSignatureIndex(1) },] struct_defs: [ StructDefinition { struct_handle: 1, access: 0x2, field_count: 0, fields: 0 },] field_defs: [] function_defs: [ FunctionDefinition { function: 1, access: 0x0, code: CodeUnit { max_stack_size: 0, locals: 0 code: [ BrTrue(1),] } },] type_signatures: [ TypeSignature(Unit), TypeSignature(Unit),] function_signatures: [ FunctionSignature { return_type: Unit, arg_types: [] }, FunctionSignature { return_type: Unit, arg_types: [] },] locals_signatures: [ LocalsSignature([]),] string_pool: [ "",] address_pool: [ Address([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),] } , oob_mutations = [] diff --git a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.rs b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.rs index 905bc6540ba44..91bc085965a26 100644 --- a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.rs +++ b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.rs @@ -63,7 +63,7 @@ fn invalid_struct_in_fn_return_() { let mut m = basic_test_module(); m.function_handles[0].return_ = SignatureIndex(1); m.signatures - .push(Signature(vec![Struct(StructHandleIndex::new(1))])); + .push(Signature(vec![Datatype(DatatypeHandleIndex::new(1))])); assert_eq!( BoundsChecker::verify_module(&m).unwrap_err().major_status(), StatusCode::INDEX_OUT_OF_BOUNDS @@ -94,7 +94,7 @@ fn invalid_struct_in_field() { let mut m = basic_test_module(); match &mut m.struct_defs[0].field_information { StructFieldInformation::Declared(ref mut fields) => { - fields[0].signature.0 = Struct(StructHandleIndex::new(3)); + fields[0].signature.0 = Datatype(DatatypeHandleIndex::new(3)); assert_eq!( BoundsChecker::verify_module(&m).unwrap_err().major_status(), StatusCode::INDEX_OUT_OF_BOUNDS @@ -111,8 +111,8 @@ fn invalid_struct_with_actuals_in_field() { let mut m = basic_test_module(); match &mut m.struct_defs[0].field_information { StructFieldInformation::Declared(ref mut fields) => { - fields[0].signature.0 = StructInstantiation(Box::new(( - StructHandleIndex::new(0), + fields[0].signature.0 = DatatypeInstantiation(Box::new(( + DatatypeHandleIndex::new(0), vec![TypeParameter(0)], ))); assert_eq!( @@ -167,7 +167,7 @@ fn invalid_struct_as_type_actual_in_exists() { let mut m = basic_test_module(); m.signatures - .push(Signature(vec![Struct(StructHandleIndex::new(3))])); + .push(Signature(vec![Datatype(DatatypeHandleIndex::new(3))])); m.function_instantiations.push(FunctionInstantiation { handle: FunctionHandleIndex::new(0), type_parameters: SignatureIndex::new(1), @@ -239,7 +239,7 @@ fn invalid_struct_for_vector_operation() { let mut skeleton = basic_test_module(); skeleton .signatures - .push(Signature(vec![Struct(StructHandleIndex::new(3))])); + .push(Signature(vec![Datatype(DatatypeHandleIndex::new(3))])); let sig_index = SignatureIndex((skeleton.signatures.len() - 1) as u16); for bytecode in [ VecPack(sig_index, 0), diff --git a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/constants_tests.rs b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/constants_tests.rs index 653654119714d..239105833b302 100644 --- a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/constants_tests.rs +++ b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/constants_tests.rs @@ -238,7 +238,7 @@ fn invalid_types() { // TODO cannot check structs are banned currently. This can be handled by IR and source lang // tests - // invalid_type(SignatureToken::Struct(StructHandleIndex(0)), vec![0]); + // invalid_type(SignatureToken::Struct(DatatypeHandleIndex(0)), vec![0]); } fn tvec(s: SignatureToken) -> SignatureToken { diff --git a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/generic_ops_tests.rs b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/generic_ops_tests.rs index 92ab3aa12cba5..aec9fdbe19549 100644 --- a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/generic_ops_tests.rs +++ b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/generic_ops_tests.rs @@ -36,33 +36,33 @@ fn make_module() -> CompiledModule { address_identifiers: vec![ AccountAddress::ZERO, // Module address ], - struct_handles: vec![ - StructHandle { + datatype_handles: vec![ + DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(1), abilities: AbilitySet::PRIMITIVES, type_parameters: vec![], }, - StructHandle { + DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(2), abilities: AbilitySet::PRIMITIVES, - type_parameters: vec![StructTypeParameter { + type_parameters: vec![DatatypeTyParameter { constraints: AbilitySet::PRIMITIVES, is_phantom: false, }], }, - StructHandle { + DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(3), abilities: AbilitySet::EMPTY | Ability::Key, type_parameters: vec![], }, - StructHandle { + DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(4), abilities: AbilitySet::EMPTY | Ability::Key, - type_parameters: vec![StructTypeParameter { + type_parameters: vec![DatatypeTyParameter { constraints: AbilitySet::PRIMITIVES, is_phantom: false, }], @@ -71,7 +71,7 @@ fn make_module() -> CompiledModule { struct_defs: vec![ // struct S { f: u64 } StructDefinition { - struct_handle: StructHandleIndex(0), + struct_handle: DatatypeHandleIndex(0), field_information: StructFieldInformation::Declared(vec![FieldDefinition { name: IdentifierIndex(5), signature: TypeSignature(SignatureToken::U64), @@ -79,7 +79,7 @@ fn make_module() -> CompiledModule { }, // struct GS { f: T } StructDefinition { - struct_handle: StructHandleIndex(1), + struct_handle: DatatypeHandleIndex(1), field_information: StructFieldInformation::Declared(vec![FieldDefinition { name: IdentifierIndex(5), signature: TypeSignature(SignatureToken::TypeParameter(0)), @@ -87,7 +87,7 @@ fn make_module() -> CompiledModule { }, // struct R has key { f: u64 } StructDefinition { - struct_handle: StructHandleIndex(2), + struct_handle: DatatypeHandleIndex(2), field_information: StructFieldInformation::Declared(vec![FieldDefinition { name: IdentifierIndex(5), signature: TypeSignature(SignatureToken::U64), @@ -95,7 +95,7 @@ fn make_module() -> CompiledModule { }, // struct GR has key { f: T } StructDefinition { - struct_handle: StructHandleIndex(3), + struct_handle: DatatypeHandleIndex(3), field_information: StructFieldInformation::Declared(vec![FieldDefinition { name: IdentifierIndex(5), signature: TypeSignature(SignatureToken::TypeParameter(0)), @@ -138,6 +138,7 @@ fn make_module() -> CompiledModule { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Ret], + jump_tables: vec![], }), }, // fun g_fn() { return; } @@ -149,6 +150,7 @@ fn make_module() -> CompiledModule { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Ret], + jump_tables: vec![], }), }, // fun test_fn() { ... } - tests will fill up the code @@ -160,6 +162,7 @@ fn make_module() -> CompiledModule { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![], + jump_tables: vec![], }), }, ], @@ -180,6 +183,10 @@ fn make_module() -> CompiledModule { struct_def_instantiations: vec![], function_instantiations: vec![], field_instantiations: vec![], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], } } @@ -193,6 +200,7 @@ fn generic_call_to_non_generic_func() { Bytecode::CallGeneric(FunctionInstantiationIndex(0)), Bytecode::Ret, ], + jump_tables: vec![], }); module.function_instantiations.push(FunctionInstantiation { handle: FunctionHandleIndex(0), @@ -214,6 +222,7 @@ fn non_generic_call_to_generic_func() { module.function_defs[2].code = Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(1)), Bytecode::Ret], + jump_tables: vec![], }); let err = InstructionConsistency::verify_module(&module) .expect_err("Call to generic function must fail"); @@ -235,6 +244,7 @@ fn generic_pack_on_non_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module .struct_def_instantiations @@ -263,6 +273,7 @@ fn non_generic_pack_on_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); let err = InstructionConsistency::verify_module(&module) .expect_err("Pack to generic struct must fail"); @@ -285,6 +296,7 @@ fn generic_unpack_on_non_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module .struct_def_instantiations @@ -314,6 +326,7 @@ fn non_generic_unpack_on_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module .struct_def_instantiations @@ -343,6 +356,7 @@ fn generic_mut_borrow_field_on_non_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module.field_instantiations.push(FieldInstantiation { handle: FieldHandleIndex(0), @@ -374,6 +388,7 @@ fn non_generic_mut_borrow_field_on_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module .struct_def_instantiations @@ -407,6 +422,7 @@ fn generic_borrow_field_on_non_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module.field_instantiations.push(FieldInstantiation { handle: FieldHandleIndex(0), @@ -438,6 +454,7 @@ fn non_generic_borrow_field_on_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module .struct_def_instantiations diff --git a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/large_type_test.rs b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/large_type_test.rs index 70953906af9bd..23b8c452d8915 100644 --- a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/large_type_test.rs +++ b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/large_type_test.rs @@ -48,6 +48,7 @@ fn test_large_types() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(0)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -68,6 +69,7 @@ fn test_large_types() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(1)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -89,6 +91,7 @@ fn test_large_types() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(1)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -109,6 +112,7 @@ fn test_large_types() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Ret], + jump_tables: vec![], }), }); @@ -131,6 +135,7 @@ fn test_large_types() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![], + jump_tables: vec![], }), }); diff --git a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/limit_tests.rs b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/limit_tests.rs index b30eaea22f91c..e7eda3d0ed084 100644 --- a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/limit_tests.rs +++ b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/limit_tests.rs @@ -38,11 +38,11 @@ fn test_function_handle_type_instantiation() { #[test] fn test_struct_handle_type_instantiation() { let mut m = basic_test_module(); - m.struct_handles.push(StructHandle { + m.datatype_handles.push(DatatypeHandle { module: ModuleHandleIndex::new(0), name: IdentifierIndex::new(0), abilities: AbilitySet::ALL, - type_parameters: std::iter::repeat(StructTypeParameter { + type_parameters: std::iter::repeat(DatatypeTyParameter { constraints: AbilitySet::ALL, is_phantom: false, }) @@ -97,7 +97,7 @@ fn big_vec_unpacks() { const N_TYPE_PARAMS: usize = 16; let mut st = SignatureToken::Vector(Box::new(SignatureToken::U8)); let type_params = vec![st; N_TYPE_PARAMS]; - st = SignatureToken::StructInstantiation(Box::new((StructHandleIndex(0), type_params))); + st = SignatureToken::DatatypeInstantiation(Box::new((DatatypeHandleIndex(0), type_params))); const N_VEC_PUSH: u16 = 1000; let mut code = vec![]; // 1. CopyLoc: ... -> ... st @@ -115,7 +115,7 @@ fn big_vec_unpacks() { code.push(Bytecode::Pop); } code.push(Bytecode::Ret); - let type_param_constraints = StructTypeParameter { + let type_param_constraints = DatatypeTyParameter { constraints: AbilitySet::EMPTY, is_phantom: false, }; @@ -126,7 +126,7 @@ fn big_vec_unpacks() { address: AddressIdentifierIndex(0), name: IdentifierIndex(0), }], - struct_handles: vec![StructHandle { + datatype_handles: vec![DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(1), abilities: AbilitySet::ALL, @@ -153,7 +153,7 @@ fn big_vec_unpacks() { constant_pool: vec![], metadata: vec![], struct_defs: vec![StructDefinition { - struct_handle: StructHandleIndex(0), + struct_handle: DatatypeHandleIndex(0), field_information: StructFieldInformation::Native, }], function_defs: vec![FunctionDefinition { @@ -164,8 +164,13 @@ fn big_vec_unpacks() { code: Some(CodeUnit { locals: SignatureIndex(0), code, + jump_tables: vec![], }), }], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; // save module and verify that it can ser/de @@ -199,7 +204,7 @@ const MAX_FUNCTIONS: usize = 1000; #[test] fn max_struct_test() { let config = VerifierConfig { - max_struct_definitions: Some(MAX_STRUCTS), + max_data_definitions: Some(MAX_STRUCTS), max_fields_in_struct: Some(MAX_FIELDS), max_function_definitions: Some(MAX_FUNCTIONS), ..Default::default() @@ -238,7 +243,7 @@ fn max_struct_test() { #[test] fn max_fields_test() { let config = VerifierConfig { - max_struct_definitions: Some(MAX_STRUCTS), + max_data_definitions: Some(MAX_STRUCTS), max_fields_in_struct: Some(MAX_FIELDS), max_function_definitions: Some(MAX_FUNCTIONS), ..Default::default() @@ -303,7 +308,7 @@ fn max_fields_test() { #[test] fn max_functions_test() { let config = VerifierConfig { - max_struct_definitions: Some(MAX_STRUCTS), + max_data_definitions: Some(MAX_STRUCTS), max_fields_in_struct: Some(MAX_FIELDS), max_function_definitions: Some(MAX_FUNCTIONS), ..Default::default() @@ -348,7 +353,7 @@ fn max_functions_test() { #[test] fn max_mixed_config_test() { let config = VerifierConfig { - max_struct_definitions: Some(MAX_STRUCTS), + max_data_definitions: Some(MAX_STRUCTS), max_fields_in_struct: Some(MAX_FIELDS), max_function_definitions: Some(MAX_FUNCTIONS), ..Default::default() @@ -362,7 +367,7 @@ fn max_mixed_config_test() { let config = VerifierConfig { max_function_definitions: None, - max_struct_definitions: None, + max_data_definitions: None, max_fields_in_struct: None, ..Default::default() }; @@ -392,7 +397,7 @@ fn max_mixed_config_test() { assert_eq!(res, Ok(())); let config = VerifierConfig { - max_struct_definitions: Some(MAX_STRUCTS), + max_data_definitions: Some(MAX_STRUCTS), max_fields_in_struct: Some(MAX_FIELDS), ..Default::default() }; @@ -434,7 +439,7 @@ fn max_mixed_config_test() { ); let config = VerifierConfig { - max_struct_definitions: Some(MAX_STRUCTS), + max_data_definitions: Some(MAX_STRUCTS), max_function_definitions: Some(MAX_FUNCTIONS), ..Default::default() }; @@ -739,14 +744,14 @@ fn multi_struct(module: &mut CompiledModule, count: usize) { module .identifiers .push(Identifier::new(format!("A_{}", i)).unwrap()); - module.struct_handles.push(StructHandle { + module.datatype_handles.push(DatatypeHandle { module: module.self_module_handle_idx, name: IdentifierIndex((module.identifiers.len() - 1) as u16), abilities: AbilitySet::EMPTY, type_parameters: vec![], }); module.struct_defs.push(StructDefinition { - struct_handle: StructHandleIndex((module.struct_handles.len() - 1) as u16), + struct_handle: DatatypeHandleIndex((module.datatype_handles.len() - 1) as u16), field_information: StructFieldInformation::Declared(vec![]), }); } @@ -806,6 +811,7 @@ fn multi_functions(module: &mut CompiledModule, count: usize) { code: Some(CodeUnit { locals: SignatureIndex((module.signatures.len() - 1) as u16), code: vec![Bytecode::Ret], + jump_tables: vec![], }), }); } diff --git a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/locals.rs b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/locals.rs index 6451e165a7232..c4e5a51558fe1 100644 --- a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/locals.rs +++ b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/locals.rs @@ -35,6 +35,7 @@ fn test_locals() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Ret], + jump_tables: vec![], }), }); @@ -67,6 +68,7 @@ fn test_locals() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::LdTrue, Bytecode::LdU8(0), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -89,6 +91,7 @@ fn test_locals() { code: Some(CodeUnit { locals: SignatureIndex(1), code: vec![], + jump_tables: vec![], }), }); diff --git a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/loop_summary_tests.rs b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/loop_summary_tests.rs index 819b9412709b9..a837f295ae398 100644 --- a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/loop_summary_tests.rs +++ b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/loop_summary_tests.rs @@ -23,13 +23,16 @@ macro_rules! assert_node { fn linear_summary() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ Nop, - /* */ Branch(2), - /* B2, L1 */ Nop, - /* */ Branch(4), - /* B4, L2 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ Nop, + /* */ Branch(2), + /* B2, L1 */ Nop, + /* */ Branch(4), + /* B4, L2 */ Ret, + ], + &[], + )) }; let n: Vec<_> = summary.preorder().collect(); @@ -65,12 +68,15 @@ fn linear_summary() { fn non_loop_back_branch_summary() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ Nop, - /* */ Branch(3), - /* B2, L2 */ Ret, - /* B3, L1 */ Branch(2), - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ Nop, + /* */ Branch(3), + /* B2, L2 */ Ret, + /* B3, L1 */ Branch(2), + ], + &[], + )) }; let n: Vec<_> = summary.preorder().collect(); @@ -106,12 +112,15 @@ fn non_loop_back_branch_summary() { fn branching_summary() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ LdTrue, - /* */ BrTrue(3), - /* B2, L2 */ Nop, - /* B3, L1 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ LdTrue, + /* */ BrTrue(3), + /* B2, L2 */ Nop, + /* B3, L1 */ Ret, + ], + &[], + )) }; let n: Vec<_> = summary.preorder().collect(); @@ -151,13 +160,16 @@ fn branching_summary() { fn looping_summary() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ LdTrue, - /* */ BrTrue(4), - /* B2, L2 */ Nop, - /* */ Branch(0), - /* B4, L1 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ LdTrue, + /* */ BrTrue(4), + /* B2, L2 */ Nop, + /* */ Branch(0), + /* B4, L1 */ Ret, + ], + &[], + )) }; let n: Vec<_> = summary.preorder().collect(); @@ -193,14 +205,17 @@ fn looping_summary() { fn branches_in_loops_summary() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ LdTrue, - /* */ BrTrue(3), - /* B2, L3 */ Nop, - /* B3, L1 */ LdFalse, - /* */ BrFalse(0), - /* B5, L2 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ LdTrue, + /* */ BrTrue(3), + /* B2, L3 */ Nop, + /* B3, L1 */ LdFalse, + /* */ BrFalse(0), + /* B5, L2 */ Ret, + ], + &[], + )) }; let n: Vec<_> = summary.preorder().collect(); @@ -244,22 +259,25 @@ fn branches_in_loops_summary() { fn loops_in_branches_summary() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ LdTrue, - /* */ BrTrue(8), - /* B2, L5 */ Nop, - /* B3, L6 */ LdFalse, - /* */ BrFalse(3), - /* B5, L7 */ LdTrue, - /* */ BrTrue(2), - /* B7, L8 */ Branch(13), - /* B8, L1 */ Nop, - /* B9, L2 */ LdTrue, - /* */ BrTrue(8), - /* B11, L3 */ LdFalse, - /* */ BrFalse(9), - /* B13, L4 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ LdTrue, + /* */ BrTrue(8), + /* B2, L5 */ Nop, + /* B3, L6 */ LdFalse, + /* */ BrFalse(3), + /* B5, L7 */ LdTrue, + /* */ BrTrue(2), + /* B7, L8 */ Branch(13), + /* B8, L1 */ Nop, + /* B9, L2 */ LdTrue, + /* */ BrTrue(8), + /* B11, L3 */ LdFalse, + /* */ BrFalse(9), + /* B13, L4 */ Ret, + ], + &[], + )) }; let n: Vec<_> = summary.preorder().collect(); @@ -343,13 +361,16 @@ fn loops_in_branches_summary() { fn loop_collapsing() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ LdTrue, - /* */ BrTrue(4), - /* B2, L2 */ Nop, - /* */ Branch(0), - /* B4, L1 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ LdTrue, + /* */ BrTrue(4), + /* B2, L2 */ Nop, + /* */ Branch(0), + /* B4, L1 */ Ret, + ], + &[], + )) }; let mut partition = LoopPartition::new(&summary); @@ -369,16 +390,19 @@ fn loop_collapsing() { fn nested_loop_collapsing() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ Nop, - /* B1, L1 */ LdTrue, - /* */ BrTrue(1), - /* B3, L2 */ LdFalse, - /* */ BrFalse(0), - /* B5, L3 */ LdTrue, - /* */ BrTrue(0), - /* B7, L4 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ Nop, + /* B1, L1 */ LdTrue, + /* */ BrTrue(1), + /* B3, L2 */ LdFalse, + /* */ BrFalse(0), + /* B5, L3 */ LdTrue, + /* */ BrTrue(0), + /* B7, L4 */ Ret, + ], + &[], + )) }; let mut partition = LoopPartition::new(&summary); diff --git a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/many_back_edges.rs b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/many_back_edges.rs index fe527fcbdf0f5..feda780b5cf93 100644 --- a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/many_back_edges.rs +++ b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/many_back_edges.rs @@ -46,6 +46,7 @@ fn many_backedges() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::LdTrue, Bytecode::LdU8(0), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -68,6 +69,7 @@ fn many_backedges() { code: Some(CodeUnit { locals: SignatureIndex(1), code: vec![], + jump_tables: vec![], }), }); diff --git a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/mod.rs b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/mod.rs index 3238641a6e76e..0ebd1d0fee366 100644 --- a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/mod.rs +++ b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/mod.rs @@ -2,6 +2,7 @@ // Copyright (c) The Move Contributors // SPDX-License-Identifier: Apache-2.0 +use move_core_types::VARIANT_COUNT_MAX; use move_vm_config::verifier::{ MeterConfig, VerifierConfig, DEFAULT_MAX_CONSTANT_VECTOR_LEN, DEFAULT_MAX_IDENTIFIER_LENGTH, }; @@ -36,7 +37,7 @@ pub(crate) fn production_config() -> (VerifierConfig, MeterConfig) { max_type_nodes: Some(256), max_push_size: Some(10000), max_dependency_depth: Some(100), - max_struct_definitions: Some(200), + max_data_definitions: Some(200), max_fields_in_struct: Some(30), max_function_definitions: Some(1000), @@ -48,6 +49,7 @@ pub(crate) fn production_config() -> (VerifierConfig, MeterConfig) { max_idenfitier_len: Some(DEFAULT_MAX_IDENTIFIER_LENGTH), allow_receiving_object_id: true, reject_mutable_random_on_entry_functions: true, + max_variants_in_enum: Some(VARIANT_COUNT_MAX), }, MeterConfig::default(), ) diff --git a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/reference_safety_tests.rs b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/reference_safety_tests.rs index 2fff034c142af..567364efe296c 100644 --- a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/reference_safety_tests.rs +++ b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/reference_safety_tests.rs @@ -35,6 +35,7 @@ fn test_bicliques() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(0)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -61,6 +62,7 @@ fn test_bicliques() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![], + jump_tables: vec![], }), }); let code = &mut m.function_defs[1].code.as_mut().unwrap().code; @@ -87,6 +89,7 @@ fn test_bicliques() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Ret], + jump_tables: vec![], }), }); @@ -109,6 +112,7 @@ fn test_bicliques() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![], + jump_tables: vec![], }), }); let code = &mut m.function_defs[i as usize + 2].code.as_mut().unwrap().code; @@ -160,6 +164,7 @@ fn test_merge_state_large_graph() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(0)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -185,6 +190,7 @@ fn test_merge_state_large_graph() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(1)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -205,6 +211,7 @@ fn test_merge_state_large_graph() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(1)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -226,6 +233,7 @@ fn test_merge_state_large_graph() { code: Some(CodeUnit { locals: SignatureIndex(1), code: vec![], + jump_tables: vec![], }), }); let code = &mut m.function_defs[i as usize + 3].code.as_mut().unwrap().code; @@ -282,6 +290,7 @@ fn test_merge_state() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(0)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -313,6 +322,7 @@ fn test_merge_state() { code: Some(CodeUnit { locals: SignatureIndex(2), code: vec![], + jump_tables: vec![], }), }); let code = &mut m.function_defs[i as usize + 1].code.as_mut().unwrap().code; @@ -395,6 +405,7 @@ fn test_copyloc_pop() { code: Some(CodeUnit { locals: SignatureIndex(2), code: vec![], + jump_tables: vec![], }), }); let code = &mut m.function_defs[i as usize].code.as_mut().unwrap().code; diff --git a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/signature_tests.rs b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/signature_tests.rs index 41d2d4e541081..2cfcc14aa176d 100644 --- a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/signature_tests.rs +++ b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/signature_tests.rs @@ -33,7 +33,7 @@ fn no_verify_locals_good() { name: IdentifierIndex(0), }], self_module_handle_idx: ModuleHandleIndex(0), - struct_handles: vec![], + datatype_handles: vec![], signatures: vec![ Signature(vec![Address]), Signature(vec![U64]), @@ -78,6 +78,7 @@ fn no_verify_locals_good() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Ret], + jump_tables: vec![], }), }, FunctionDefinition { @@ -88,9 +89,14 @@ fn no_verify_locals_good() { code: Some(CodeUnit { locals: SignatureIndex(1), code: vec![Ret], + jump_tables: vec![], }), }, ], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; assert!(verify_module_unmetered(&compiled_module_good).is_ok()); } @@ -106,7 +112,7 @@ fn big_signature_test() { } for _ in 0..INSTANTIATION_DEPTH { let type_params = vec![st; N_TYPE_PARAMS]; - st = SignatureToken::StructInstantiation(Box::new((StructHandleIndex(0), type_params))); + st = SignatureToken::DatatypeInstantiation(Box::new((DatatypeHandleIndex(0), type_params))); } const N_READPOP: u16 = 7500; @@ -122,7 +128,7 @@ fn big_signature_test() { } code.push(Bytecode::Ret); - let type_param_constraints = StructTypeParameter { + let type_param_constraints = DatatypeTyParameter { constraints: AbilitySet::EMPTY, is_phantom: false, }; @@ -134,7 +140,7 @@ fn big_signature_test() { address: AddressIdentifierIndex(0), name: IdentifierIndex(0), }], - struct_handles: vec![StructHandle { + datatype_handles: vec![DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(1), abilities: AbilitySet::ALL, @@ -161,7 +167,7 @@ fn big_signature_test() { constant_pool: vec![], metadata: vec![], struct_defs: vec![StructDefinition { - struct_handle: StructHandleIndex(0), + struct_handle: DatatypeHandleIndex(0), field_information: StructFieldInformation::Native, }], function_defs: vec![FunctionDefinition { @@ -172,8 +178,13 @@ fn big_signature_test() { code: Some(CodeUnit { locals: SignatureIndex(0), code, + jump_tables: vec![], }), }], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; // save module and verify that it can ser/de diff --git a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/vec_pack_tests.rs b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/vec_pack_tests.rs index 540962b3cbb24..96667cee33f04 100644 --- a/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/vec_pack_tests.rs +++ b/external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/vec_pack_tests.rs @@ -32,6 +32,7 @@ fn test_vec_pack() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![], + jump_tables: vec![], }), }); diff --git a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/ability_field_requirements.rs b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/ability_field_requirements.rs index e90c86efae4c5..5ef60518b65ae 100644 --- a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/ability_field_requirements.rs +++ b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/ability_field_requirements.rs @@ -17,7 +17,7 @@ pub fn verify_module(module: &CompiledModule) -> VMResult<()> { fn verify_module_impl(module: &CompiledModule) -> PartialVMResult<()> { for (idx, struct_def) in module.struct_defs().iter().enumerate() { - let sh = module.struct_handle_at(struct_def.struct_handle); + let sh = module.datatype_handle_at(struct_def.struct_handle); let fields = match &struct_def.field_information { StructFieldInformation::Native => continue, StructFieldInformation::Declared(fields) => fields, diff --git a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/absint.rs b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/absint.rs index 9f11fb5f7d37f..e9cad4ff0556b 100644 --- a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/absint.rs +++ b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/absint.rs @@ -194,7 +194,7 @@ impl<'a> FunctionContext<'a> { return_: module.signature_at(function_handle.return_), locals: module.signature_at(code.locals), type_parameters: &function_handle.type_parameters, - cfg: VMControlFlowGraph::new(&code.code), + cfg: VMControlFlowGraph::new(&code.code, &code.jump_tables), } } diff --git a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/acquires_list_verifier.rs b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/acquires_list_verifier.rs index cab0b6b9a6456..74598b5a9a2a9 100644 --- a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/acquires_list_verifier.rs +++ b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/acquires_list_verifier.rs @@ -72,7 +72,7 @@ impl<'a> AcquiresVerifier<'a> { } let struct_def = safe_unwrap!(module.struct_defs().get(annotation.0 as usize)); - let struct_handle = module.struct_handle_at(struct_def.struct_handle); + let struct_handle = module.datatype_handle_at(struct_def.struct_handle); if !struct_handle.abilities.has_key() { return Err(PartialVMError::new(StatusCode::INVALID_ACQUIRES_ANNOTATION)); } @@ -171,6 +171,18 @@ impl<'a> AcquiresVerifier<'a> { | Bytecode::VecPopBack(_) | Bytecode::VecUnpack(..) | Bytecode::VecSwap(_) => Ok(()), + Bytecode::PackVariant(_) + | Bytecode::PackVariantGeneric(_) + | Bytecode::UnpackVariant(_) + | Bytecode::UnpackVariantGeneric(_) + | Bytecode::UnpackVariantImmRef(_) + | Bytecode::UnpackVariantGenericImmRef(_) + | Bytecode::UnpackVariantMutRef(_) + | Bytecode::UnpackVariantGenericMutRef(_) + | Bytecode::VariantSwitch(_) => Err(PartialVMError::new( + StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR, + ) + .with_message("Unexpected variant opcode in version 1".to_string())), } } diff --git a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/check_duplication.rs b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/check_duplication.rs index 6e26a4b63b15e..c44fe9ba50cb2 100644 --- a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/check_duplication.rs +++ b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/check_duplication.rs @@ -13,7 +13,7 @@ use move_binary_format::{ errors::{verification_error, Location, PartialVMResult, VMResult}, file_format::{ CompiledModule, Constant, FunctionHandle, FunctionHandleIndex, FunctionInstantiation, - ModuleHandle, Signature, StructFieldInformation, StructHandle, StructHandleIndex, + ModuleHandle, Signature, StructFieldInformation, DatatypeHandle, DatatypeHandleIndex, TableIndex, }, IndexKind, @@ -39,7 +39,7 @@ impl<'a> DuplicationChecker<'a> { Self::check_signatures(module.signatures())?; Self::check_module_handles(module.module_handles())?; Self::check_module_handles(module.friend_decls())?; - Self::check_struct_handles(module.struct_handles())?; + Self::check_datatype_handles(module.datatype_handles())?; Self::check_function_handles(module.function_handles())?; Self::check_function_instantiations(module.function_instantiations())?; @@ -106,12 +106,12 @@ impl<'a> DuplicationChecker<'a> { } } - // StructHandles - module and name define uniqueness - fn check_struct_handles(struct_handles: &[StructHandle]) -> PartialVMResult<()> { - match Self::first_duplicate_element(struct_handles.iter().map(|x| (x.module, x.name))) { + // DatatypeHandles - module and name define uniqueness + fn check_datatype_handles(datatype_handles: &[DatatypeHandle]) -> PartialVMResult<()> { + match Self::first_duplicate_element(datatype_handles.iter().map(|x| (x.module, x.name))) { Some(idx) => Err(verification_error( StatusCode::DUPLICATE_ELEMENT, - IndexKind::StructHandle, + IndexKind::DatatypeHandle, idx, )), None => Ok(()), @@ -181,7 +181,7 @@ impl<'a> DuplicationChecker<'a> { } fn check_struct_definitions(&self) -> PartialVMResult<()> { - // StructDefinition - contained StructHandle defines uniqueness + // StructDefinition - contained DatatypeHandle defines uniqueness if let Some(idx) = Self::first_duplicate_element(self.module.struct_defs().iter().map(|x| x.struct_handle)) { @@ -214,7 +214,7 @@ impl<'a> DuplicationChecker<'a> { } // Check that each struct definition is pointing to the self module if let Some(idx) = self.module.struct_defs().iter().position(|x| { - self.module.struct_handle_at(x.struct_handle).module != self.module.self_handle_idx() + self.module.datatype_handle_at(x.struct_handle).module != self.module.self_handle_idx() }) { return Err(verification_error( StatusCode::INVALID_MODULE_HANDLE, @@ -223,20 +223,20 @@ impl<'a> DuplicationChecker<'a> { )); } // Check that each struct handle in self module is implemented (has a declaration) - let implemented_struct_handles: HashSet = self + let implemented_datatype_handles: HashSet = self .module .struct_defs() .iter() .map(|x| x.struct_handle) .collect(); - if let Some(idx) = (0..self.module.struct_handles().len()).position(|x| { - let y = StructHandleIndex::new(x as u16); - self.module.struct_handle_at(y).module == self.module.self_handle_idx() - && !implemented_struct_handles.contains(&y) + if let Some(idx) = (0..self.module.datatype_handles().len()).position(|x| { + let y = DatatypeHandleIndex::new(x as u16); + self.module.datatype_handle_at(y).module == self.module.self_handle_idx() + && !implemented_datatype_handles.contains(&y) }) { return Err(verification_error( StatusCode::UNIMPLEMENTED_HANDLE, - IndexKind::StructHandle, + IndexKind::DatatypeHandle, idx as TableIndex, )); } diff --git a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/dependencies.rs b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/dependencies.rs index fec9f3c3f232f..e09d59c0b1e8c 100644 --- a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/dependencies.rs +++ b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/dependencies.rs @@ -6,9 +6,9 @@ use move_binary_format::{ errors::{verification_error, Location, PartialVMError, PartialVMResult, VMResult}, file_format::{ - AbilitySet, Bytecode, CodeOffset, CompiledModule, FunctionDefinitionIndex, - FunctionHandleIndex, ModuleHandleIndex, SignatureToken, StructHandleIndex, - StructTypeParameter, TableIndex, Visibility, + AbilitySet, Bytecode, CodeOffset, CompiledModule, DatatypeHandleIndex, DatatypeTyParameter, + FunctionDefinitionIndex, FunctionHandleIndex, ModuleHandleIndex, SignatureToken, + TableIndex, Visibility, }, file_format_common::VERSION_5, safe_unwrap, IndexKind, @@ -21,7 +21,7 @@ struct Context<'a, 'b> { // (Module -> CompiledModule) for (at least) all immediate dependencies dependency_map: BTreeMap, // (Module::StructName -> handle) for all types of all dependencies - struct_id_to_handle_map: BTreeMap<(ModuleId, Identifier), StructHandleIndex>, + struct_id_to_handle_map: BTreeMap<(ModuleId, Identifier), DatatypeHandleIndex>, // (Module::FunctionName -> handle) for all functions that can ever be called by this // module/script in all dependencies func_id_to_handle_map: BTreeMap<(ModuleId, Identifier), FunctionHandleIndex>, @@ -73,7 +73,7 @@ impl<'a, 'b> Context<'a, 'b> { // Module::StructName -> def handle idx for struct_def in module.struct_defs() { - let struct_handle = module.struct_handle_at(struct_def.struct_handle); + let struct_handle = module.datatype_handle_at(struct_def.struct_handle); let struct_name = module.identifier_at(struct_handle.name); context.struct_id_to_handle_map.insert( (module_id.clone(), struct_name.to_owned()), @@ -184,7 +184,7 @@ fn verify_imported_modules(context: &Context) -> PartialVMResult<()> { fn verify_imported_structs(context: &Context) -> PartialVMResult<()> { let self_module = context.resolver.self_handle_idx(); - for (idx, struct_handle) in context.resolver.struct_handles().iter().enumerate() { + for (idx, struct_handle) in context.resolver.datatype_handles().iter().enumerate() { if struct_handle.module == self_module { continue; } @@ -199,7 +199,7 @@ fn verify_imported_structs(context: &Context) -> PartialVMResult<()> { .get(&(owner_module_id, struct_name.to_owned())) { Some(def_idx) => { - let def_handle = owner_module.struct_handle_at(*def_idx); + let def_handle = owner_module.datatype_handle_at(*def_idx); if !compatible_struct_abilities(struct_handle.abilities, def_handle.abilities) || !compatible_struct_type_parameters( &struct_handle.type_parameters, @@ -208,7 +208,7 @@ fn verify_imported_structs(context: &Context) -> PartialVMResult<()> { { return Err(verification_error( StatusCode::TYPE_MISMATCH, - IndexKind::StructHandle, + IndexKind::DatatypeHandle, idx as TableIndex, )); } @@ -216,7 +216,7 @@ fn verify_imported_structs(context: &Context) -> PartialVMResult<()> { None => { return Err(verification_error( StatusCode::LOOKUP_FAILED, - IndexKind::StructHandle, + IndexKind::DatatypeHandle, idx as TableIndex, )) } @@ -345,8 +345,8 @@ fn compatible_fun_type_parameters( // - The number of type parameters must be the same // - Each pair of parameters must satisfy [`compatible_type_parameter_constraints`] and [`compatible_type_parameter_phantom_decl`] fn compatible_struct_type_parameters( - local_type_parameters_declaration: &[StructTypeParameter], - defined_type_parameters: &[StructTypeParameter], + local_type_parameters_declaration: &[DatatypeTyParameter], + defined_type_parameters: &[DatatypeTyParameter], ) -> bool { local_type_parameters_declaration.len() == defined_type_parameters.len() && local_type_parameters_declaration @@ -378,8 +378,8 @@ fn compatible_type_parameter_constraints( // Adding phantom declarations relaxes the requirements for clients, thus, the local view may // lack a phantom declaration present in the definition. fn compatible_type_parameter_phantom_decl( - local_type_parameter_declaration: &StructTypeParameter, - defined_type_parameter: &StructTypeParameter, + local_type_parameter_declaration: &DatatypeTyParameter, + defined_type_parameter: &DatatypeTyParameter, ) -> bool { // local_type_parameter_declaration.is_phantom => defined_type_parameter.is_phantom !local_type_parameter_declaration.is_phantom || defined_type_parameter.is_phantom @@ -419,10 +419,10 @@ fn compare_types( (SignatureToken::Vector(ty1), SignatureToken::Vector(ty2)) => { compare_types(context, ty1, ty2, def_module) } - (SignatureToken::Struct(idx1), SignatureToken::Struct(idx2)) => { + (SignatureToken::Datatype(idx1), SignatureToken::Datatype(idx2)) => { compare_structs(context, *idx1, *idx2, def_module) } - (SignatureToken::StructInstantiation(s1), SignatureToken::StructInstantiation(s2)) => { + (SignatureToken::DatatypeInstantiation(s1), SignatureToken::DatatypeInstantiation(s2)) => { let (idx1, inst1) = &**s1; let (idx2, inst2) = &**s2; compare_structs(context, *idx1, *idx2, def_module)?; @@ -446,8 +446,8 @@ fn compare_types( | (SignatureToken::Address, _) | (SignatureToken::Signer, _) | (SignatureToken::Vector(_), _) - | (SignatureToken::Struct(_), _) - | (SignatureToken::StructInstantiation(_), _) + | (SignatureToken::Datatype(_), _) + | (SignatureToken::DatatypeInstantiation(_), _) | (SignatureToken::Reference(_), _) | (SignatureToken::MutableReference(_), _) | (SignatureToken::TypeParameter(_), _) @@ -459,18 +459,18 @@ fn compare_types( fn compare_structs( context: &Context, - idx1: StructHandleIndex, - idx2: StructHandleIndex, + idx1: DatatypeHandleIndex, + idx2: DatatypeHandleIndex, def_module: &CompiledModule, ) -> PartialVMResult<()> { // grab ModuleId and struct name for the module being verified - let struct_handle = context.resolver.struct_handle_at(idx1); + let struct_handle = context.resolver.datatype_handle_at(idx1); let module_handle = context.resolver.module_handle_at(struct_handle.module); let module_id = context.resolver.module_id_for_handle(module_handle); let struct_name = context.resolver.identifier_at(struct_handle.name); // grab ModuleId and struct name for the definition - let def_struct_handle = def_module.struct_handle_at(idx2); + let def_struct_handle = def_module.datatype_handle_at(idx2); let def_module_handle = def_module.module_handle_at(def_struct_handle.module); let def_module_id = def_module.module_id_for_handle(def_module_handle); let def_struct_name = def_module.identifier_at(def_struct_handle.name); diff --git a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/instantiation_loops.rs b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/instantiation_loops.rs index 0d4f2630fc6f5..3ef8c25e581d6 100644 --- a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/instantiation_loops.rs +++ b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/instantiation_loops.rs @@ -142,14 +142,14 @@ impl<'a> InstantiationLoopChecker<'a> { fn rec(type_params: &mut HashSet, ty: &SignatureToken) { match ty { - Bool | Address | U8 | U16 | U32 | U64 | U128 | U256 | Signer | Struct(_) => (), + Bool | Address | U8 | U16 | U32 | U64 | U128 | U256 | Signer | Datatype(_) => (), TypeParameter(idx) => { type_params.insert(*idx); } Vector(ty) => rec(type_params, ty), Reference(ty) | MutableReference(ty) => rec(type_params, ty), - StructInstantiation(s) => { - let (_, tys) = &**s; + DatatypeInstantiation(inst) => { + let (_, tys) = &**inst; for ty in tys { rec(type_params, ty); } diff --git a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/instruction_consistency.rs b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/instruction_consistency.rs index fc33c803f10e8..88da80afd3ebe 100644 --- a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/instruction_consistency.rs +++ b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/instruction_consistency.rs @@ -135,6 +135,21 @@ impl<'a> InstructionConsistency<'a> { | Or | And | Not | Eq | Neq | Lt | Gt | Le | Ge | CopyLoc(_) | MoveLoc(_) | StLoc(_) | MutBorrowLoc(_) | ImmBorrowLoc(_) | VecLen(_) | VecImmBorrow(_) | VecMutBorrow(_) | VecPushBack(_) | VecPopBack(_) | VecSwap(_) | Abort | Nop => (), + PackVariant(_) + | PackVariantGeneric(_) + | UnpackVariant(_) + | UnpackVariantGeneric(_) + | UnpackVariantImmRef(_) + | UnpackVariantGenericImmRef(_) + | UnpackVariantMutRef(_) + | UnpackVariantGenericMutRef(_) + | VariantSwitch(_) => { + return Err( + PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) + .at_code_offset(self.current_function(), offset as CodeOffset) + .with_message("Unexpected variant opcode in version 1".to_string()), + ); + } } } Ok(()) @@ -167,7 +182,7 @@ impl<'a> InstructionConsistency<'a> { generic: bool, ) -> PartialVMResult<()> { let struct_def = self.resolver.struct_def_at(struct_def_index); - let struct_handle = self.resolver.struct_handle_at(struct_def.struct_handle); + let struct_handle = self.resolver.datatype_handle_at(struct_def.struct_handle); if struct_handle.type_parameters.is_empty() == generic { return Err( PartialVMError::new(StatusCode::GENERIC_MEMBER_OPCODE_MISMATCH) diff --git a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/limits.rs b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/limits.rs index 90e92c8d7cd0f..312ff030b89d6 100644 --- a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/limits.rs +++ b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/limits.rs @@ -26,18 +26,18 @@ impl<'a> LimitsVerifier<'a> { let limit_check = Self { resolver: module }; limit_check.verify_constants(config)?; limit_check.verify_function_handles(config)?; - limit_check.verify_struct_handles(config)?; + limit_check.verify_datatype_handles(config)?; limit_check.verify_type_nodes(config)?; limit_check.verify_identifiers(config)?; limit_check.verify_definitions(config) } - fn verify_struct_handles(&self, config: &VerifierConfig) -> PartialVMResult<()> { + fn verify_datatype_handles(&self, config: &VerifierConfig) -> PartialVMResult<()> { if let Some(limit) = config.max_generic_instantiation_length { - for (idx, struct_handle) in self.resolver.struct_handles().iter().enumerate() { + for (idx, struct_handle) in self.resolver.datatype_handles().iter().enumerate() { if struct_handle.type_parameters.len() > limit { return Err(PartialVMError::new(StatusCode::TOO_MANY_TYPE_PARAMETERS) - .at_index(IndexKind::StructHandle, idx as u16)); + .at_index(IndexKind::DatatypeHandle, idx as u16)); } } } @@ -105,7 +105,7 @@ impl<'a> LimitsVerifier<'a> { // Notice that the preorder traversal will iterate all type instantiations, so we // why we can ignore them below. match t { - SignatureToken::Struct(..) | SignatureToken::StructInstantiation(..) => { + SignatureToken::Datatype(..) | SignatureToken::DatatypeInstantiation(..) => { size += STRUCT_SIZE_WEIGHT } SignatureToken::TypeParameter(..) => size += PARAM_SIZE_WEIGHT, @@ -132,7 +132,7 @@ impl<'a> LimitsVerifier<'a> { } let defs = self.resolver.struct_defs(); { - if let Some(max_struct_definitions) = config.max_struct_definitions { + if let Some(max_struct_definitions) = config.max_data_definitions { if defs.len() > max_struct_definitions { return Err(PartialVMError::new( StatusCode::MAX_STRUCT_DEFINITIONS_REACHED, diff --git a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/locals_safety/mod.rs b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/locals_safety/mod.rs index 1ffb24ed80074..edaa9e3cfcd32 100644 --- a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/locals_safety/mod.rs +++ b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/locals_safety/mod.rs @@ -160,6 +160,20 @@ fn execute_inner( | Bytecode::VecPopBack(_) | Bytecode::VecUnpack(..) | Bytecode::VecSwap(_) => (), + Bytecode::PackVariant(_) + | Bytecode::PackVariantGeneric(_) + | Bytecode::UnpackVariant(_) + | Bytecode::UnpackVariantGeneric(_) + | Bytecode::UnpackVariantImmRef(_) + | Bytecode::UnpackVariantGenericImmRef(_) + | Bytecode::UnpackVariantMutRef(_) + | Bytecode::UnpackVariantGenericMutRef(_) + | Bytecode::VariantSwitch(_) => { + return Err( + PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) + .with_message("Unexpected variant opcode in version 1".to_string()), + ); + } }; Ok(()) } diff --git a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/reference_safety/abstract_state.rs b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/reference_safety/abstract_state.rs index 66451e2146025..d8d7b9f00a9a9 100644 --- a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/reference_safety/abstract_state.rs +++ b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/reference_safety/abstract_state.rs @@ -440,7 +440,7 @@ impl AbstractState { if is_mut_borrow_with_full_borrows() || is_imm_borrow_with_mut_borrows() { // TODO improve error for mutable case - return Err(self.error(StatusCode::BORROWFIELD_EXISTS_MUTABLE_BORROW_ERROR, offset)); + return Err(self.error(StatusCode::FIELD_EXISTS_MUTABLE_BORROW_ERROR, offset)); } let field_borrow_id = self.new_ref(mut_); diff --git a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/reference_safety/mod.rs b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/reference_safety/mod.rs index 1f52c07f90d50..c049d6fc2e8ec 100644 --- a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/reference_safety/mod.rs +++ b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/reference_safety/mod.rs @@ -425,6 +425,20 @@ fn execute_inner( let vec_ref = safe_unwrap_err!(verifier.stack.pop()); state.vector_op(offset, vec_ref, true)?; } + Bytecode::PackVariant(_) + | Bytecode::PackVariantGeneric(_) + | Bytecode::UnpackVariant(_) + | Bytecode::UnpackVariantGeneric(_) + | Bytecode::UnpackVariantImmRef(_) + | Bytecode::UnpackVariantGenericImmRef(_) + | Bytecode::UnpackVariantMutRef(_) + | Bytecode::UnpackVariantGenericMutRef(_) + | Bytecode::VariantSwitch(_) => { + return Err( + PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) + .with_message("Unexpected variant opcode in version 1".to_string()), + ); + } }; Ok(()) } diff --git a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/regression_tests/reference_analysis.rs b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/regression_tests/reference_analysis.rs index 2df2c7b43a5ed..51bd7d47db5c9 100644 --- a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/regression_tests/reference_analysis.rs +++ b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/regression_tests/reference_analysis.rs @@ -5,12 +5,11 @@ use move_binary_format::{ file_format::{ empty_module, AbilitySet, AddressIdentifierIndex, Bytecode::{self, *}, - CodeUnit, Constant, FieldDefinition, FunctionDefinition, FunctionHandle, - FunctionHandleIndex, IdentifierIndex, ModuleHandle, ModuleHandleIndex, Signature, - SignatureIndex, + CodeUnit, Constant, DatatypeHandle, DatatypeHandleIndex, FieldDefinition, + FunctionDefinition, FunctionHandle, FunctionHandleIndex, IdentifierIndex, ModuleHandle, + ModuleHandleIndex, Signature, SignatureIndex, SignatureToken::{self, *}, - StructDefinition, StructDefinitionIndex, StructFieldInformation, StructHandle, - StructHandleIndex, TypeSignature, Visibility, + StructDefinition, StructDefinitionIndex, StructFieldInformation, TypeSignature, Visibility, Visibility::*, }, CompiledModule, @@ -26,7 +25,7 @@ fn unbalanced_stack_crash() { let mut module = empty_module(); module.version = 5; - module.struct_handles.push(StructHandle { + module.datatype_handles.push(DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(1), abilities: AbilitySet::ALL, @@ -67,7 +66,7 @@ fn unbalanced_stack_crash() { }); module.struct_defs.push(StructDefinition { - struct_handle: StructHandleIndex(0), + struct_handle: DatatypeHandleIndex(0), field_information: StructFieldInformation::Declared(vec![FieldDefinition { name: IdentifierIndex::new(3), signature: TypeSignature(Address), @@ -92,6 +91,7 @@ fn unbalanced_stack_crash() { Ret, ], locals: SignatureIndex::new(2), + jump_tables: vec![], }; let fun_def = FunctionDefinition { code: Some(code_unit), @@ -125,7 +125,7 @@ fn too_many_locals() { address: AddressIdentifierIndex(0), name: IdentifierIndex(0), }], - struct_handles: vec![], + datatype_handles: vec![], function_handles: vec![FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), @@ -152,8 +152,13 @@ fn too_many_locals() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![CopyLoc(2), StLoc(33), Branch(0)], + jump_tables: vec![], }), }], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; let res = crate::verify_module_unmetered(&module); @@ -173,7 +178,7 @@ fn borrow_graph() { address: AddressIdentifierIndex(0), name: IdentifierIndex(0), }], - struct_handles: vec![], + datatype_handles: vec![], function_handles: vec![FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), @@ -203,8 +208,13 @@ fn borrow_graph() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![MoveLoc(0), MoveLoc(1), StLoc(0), StLoc(1), Branch(0)], + jump_tables: vec![], }), }], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; let res = crate::verify_module_unmetered(&module); @@ -269,7 +279,7 @@ fn indirect_code() { address: AddressIdentifierIndex(0), name: IdentifierIndex(0), }], - struct_handles: vec![], + datatype_handles: vec![], function_handles: vec![FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), @@ -307,8 +317,13 @@ fn indirect_code() { code: Some(CodeUnit { locals: SignatureIndex(1), code, + jump_tables: vec![], }), }], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; let res = crate::verify_module_with_config_unmetered(&VerifierConfig::default(), &module) diff --git a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/signature.rs b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/signature.rs index ad881affc24e6..be9bf1f494680 100644 --- a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/signature.rs +++ b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/signature.rs @@ -8,9 +8,9 @@ use move_binary_format::{ errors::{Location, PartialVMError, PartialVMResult, VMResult}, file_format::{ - AbilitySet, Bytecode, CodeUnit, CompiledModule, FunctionDefinition, FunctionHandle, - Signature, SignatureIndex, SignatureToken, StructDefinition, StructFieldInformation, - StructTypeParameter, TableIndex, + AbilitySet, Bytecode, CodeUnit, CompiledModule, DatatypeTyParameter, FunctionDefinition, + FunctionHandle, Signature, SignatureIndex, SignatureToken, StructDefinition, + StructFieldInformation, TableIndex, }, file_format_common::VERSION_6, IndexKind, @@ -70,7 +70,7 @@ impl<'a> SignatureChecker<'a> { StructFieldInformation::Native => continue, StructFieldInformation::Declared(fields) => fields, }; - let struct_handle = self.resolver.struct_handle_at(struct_def.struct_handle); + let struct_handle = self.resolver.datatype_handle_at(struct_def.struct_handle); let err_handler = |err: PartialVMError, idx| { err.at_index(IndexKind::FieldDefinition, idx as TableIndex) .at_index(IndexKind::StructDefinition, struct_def_idx as TableIndex) @@ -139,7 +139,7 @@ impl<'a> SignatureChecker<'a> { | MutBorrowGlobalGenericDeprecated(idx) => { let struct_inst = self.resolver.struct_instantiation_at(*idx); let struct_def = self.resolver.struct_def_at(struct_inst.def); - let struct_handle = self.resolver.struct_handle_at(struct_def.struct_handle); + let struct_handle = self.resolver.datatype_handle_at(struct_def.struct_handle); let type_arguments = &self.resolver.signature_at(struct_inst.type_parameters).0; self.check_signature_tokens(type_arguments)?; self.check_generic_instance( @@ -152,7 +152,7 @@ impl<'a> SignatureChecker<'a> { let field_inst = self.resolver.field_instantiation_at(*idx); let field_handle = self.resolver.field_handle_at(field_inst.handle); let struct_def = self.resolver.struct_def_at(field_handle.owner); - let struct_handle = self.resolver.struct_handle_at(struct_def.struct_handle); + let struct_handle = self.resolver.datatype_handle_at(struct_def.struct_handle); let type_arguments = &self.resolver.signature_at(field_inst.type_parameters).0; self.check_signature_tokens(type_arguments)?; self.check_generic_instance( @@ -243,6 +243,20 @@ impl<'a> SignatureChecker<'a> { | MoveFromDeprecated(_) | Abort | Nop => Ok(()), + PackVariant(_) + | PackVariantGeneric(_) + | UnpackVariant(_) + | UnpackVariantGeneric(_) + | UnpackVariantImmRef(_) + | UnpackVariantGenericImmRef(_) + | UnpackVariantMutRef(_) + | UnpackVariantGenericMutRef(_) + | VariantSwitch(_) => { + return Err( + PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) + .with_message("Unexpected variant opcode in version 1".to_string()), + ); + } }; result.map_err(|err| { err.append_message_with_separator(' ', format!("at offset {} ", offset)) @@ -256,13 +270,13 @@ impl<'a> SignatureChecker<'a> { &self, ty: &SignatureToken, is_phantom_pos: bool, - type_parameters: &[StructTypeParameter], + type_parameters: &[DatatypeTyParameter], ) -> PartialVMResult<()> { match ty { SignatureToken::Vector(ty) => self.check_phantom_params(ty, false, type_parameters)?, - SignatureToken::StructInstantiation(s) => { + SignatureToken::DatatypeInstantiation(s) => { let (idx, type_arguments) = &**s; - let sh = self.resolver.struct_handle_at(*idx); + let sh = self.resolver.datatype_handle_at(*idx); for (i, ty) in type_arguments.iter().enumerate() { self.check_phantom_params( ty, @@ -282,7 +296,7 @@ impl<'a> SignatureChecker<'a> { } } - SignatureToken::Struct(_) + SignatureToken::Datatype(_) | SignatureToken::Reference(_) | SignatureToken::MutableReference(_) | SignatureToken::Bool @@ -326,7 +340,7 @@ impl<'a> SignatureChecker<'a> { fn check_signature_token(&self, ty: &SignatureToken) -> PartialVMResult<()> { use SignatureToken::*; match ty { - U8 | U16 | U32 | U64 | U128 | U256 | Bool | Address | Signer | Struct(_) + U8 | U16 | U32 | U64 | U128 | U256 | Bool | Address | Signer | Datatype(_) | TypeParameter(_) => Ok(()), Reference(_) | MutableReference(_) => { // TODO: Prop tests expect us to NOT check the inner types. @@ -335,7 +349,7 @@ impl<'a> SignatureChecker<'a> { .with_message("reference not allowed".to_string())) } Vector(ty) => self.check_signature_token(ty), - StructInstantiation(s) => { + DatatypeInstantiation(s) => { let (_, type_arguments) = &**s; self.check_signature_tokens(type_arguments) } @@ -375,13 +389,13 @@ impl<'a> SignatureChecker<'a> { type_parameters: &[AbilitySet], ) -> PartialVMResult<()> { match s { - SignatureToken::StructInstantiation(s) => { + SignatureToken::DatatypeInstantiation(s) => { let (idx, type_arguments) = &**s; // Check that the instantiation satisfies the `idx` struct's constraints // Cannot be checked completely if we do not know the constraints of type parameters // i.e. it cannot be checked unless we are inside some module member. The only case // where that happens is when checking the signature pool itself - let sh = self.resolver.struct_handle_at(*idx); + let sh = self.resolver.datatype_handle_at(*idx); self.check_generic_instance( type_arguments, sh.type_param_constraints(), @@ -392,7 +406,7 @@ impl<'a> SignatureChecker<'a> { | SignatureToken::MutableReference(_) | SignatureToken::Vector(_) | SignatureToken::TypeParameter(_) - | SignatureToken::Struct(_) + | SignatureToken::Datatype(_) | SignatureToken::Bool | SignatureToken::U8 | SignatureToken::U16 diff --git a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/stack_usage_verifier.rs b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/stack_usage_verifier.rs index 1c3ee7db190f9..c7f4ee9f0044c 100644 --- a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/stack_usage_verifier.rs +++ b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/stack_usage_verifier.rs @@ -265,6 +265,20 @@ impl<'a> StackUsageVerifier<'a> { }; (1, field_count as u64) } + Bytecode::PackVariant(_) + | Bytecode::PackVariantGeneric(_) + | Bytecode::UnpackVariant(_) + | Bytecode::UnpackVariantGeneric(_) + | Bytecode::UnpackVariantImmRef(_) + | Bytecode::UnpackVariantGenericImmRef(_) + | Bytecode::UnpackVariantMutRef(_) + | Bytecode::UnpackVariantGenericMutRef(_) + | Bytecode::VariantSwitch(_) => { + return Err( + PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) + .with_message("Unexpected variant opcode in version 1".to_string()), + ); + } }) } diff --git a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/struct_defs.rs b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/struct_defs.rs index 30e28762dc056..96c09a87e341c 100644 --- a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/struct_defs.rs +++ b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/struct_defs.rs @@ -8,7 +8,7 @@ use move_binary_format::{ errors::{verification_error, Location, PartialVMError, PartialVMResult, VMResult}, file_format::{ - CompiledModule, SignatureToken, StructDefinitionIndex, StructHandleIndex, TableIndex, + CompiledModule, DatatypeHandleIndex, SignatureToken, StructDefinitionIndex, TableIndex, }, internals::ModuleIndex, IndexKind, @@ -35,7 +35,7 @@ impl<'a> RecursiveStructDefChecker<'a> { match toposort(&graph, None) { Ok(_) => Ok(()), Err(cycle) => Err(verification_error( - StatusCode::RECURSIVE_STRUCT_DEFINITION, + StatusCode::RECURSIVE_DATATYPE_DEFINITION, IndexKind::StructDefinition, cycle.node_id().into_index() as TableIndex, )), @@ -48,7 +48,7 @@ impl<'a> RecursiveStructDefChecker<'a> { struct StructDefGraphBuilder<'a> { module: &'a CompiledModule, /// Used to follow field definitions' signatures' struct handles to their struct definitions. - handle_to_def: BTreeMap, + handle_to_def: BTreeMap, } impl<'a> StructDefGraphBuilder<'a> { @@ -119,7 +119,7 @@ impl<'a> StructDefGraphBuilder<'a> { ) } T::Vector(inner) => self.add_signature_token(neighbors, cur_idx, inner)?, - T::Struct(sh_idx) => { + T::Datatype(sh_idx) => { if let Some(struct_def_idx) = self.handle_to_def.get(sh_idx) { neighbors .entry(cur_idx) @@ -127,7 +127,7 @@ impl<'a> StructDefGraphBuilder<'a> { .insert(*struct_def_idx); } } - T::StructInstantiation(s) => { + T::DatatypeInstantiation(s) => { let (sh_idx, inners) = &**s; if let Some(struct_def_idx) = self.handle_to_def.get(sh_idx) { neighbors diff --git a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/type_safety.rs b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/type_safety.rs index ebf578e6a936c..b6183446e26fa 100644 --- a/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/type_safety.rs +++ b/external-crates/move/move-execution/v1/crates/move-bytecode-verifier/src/type_safety.rs @@ -13,12 +13,11 @@ use move_binary_format::{ control_flow_graph::ControlFlowGraph, errors::{PartialVMError, PartialVMResult}, file_format::{ - AbilitySet, Bytecode, CodeOffset, CompiledModule, FieldHandleIndex, + AbilitySet, Bytecode, CodeOffset, DatatypeHandleIndex, FieldHandleIndex, FunctionDefinitionIndex, FunctionHandle, LocalIndex, Signature, SignatureToken, SignatureToken as ST, StructDefinition, StructDefinitionIndex, StructFieldInformation, - StructHandleIndex, }, - safe_unwrap_err, + safe_unwrap_err, CompiledModule, }; use move_bytecode_verifier_meter::{Meter, Scope}; use move_core_types::vm_status::StatusCode; @@ -940,6 +939,20 @@ fn verify_instr( } verifier.push(meter, ST::U256)?; } + Bytecode::PackVariant(_) + | Bytecode::PackVariantGeneric(_) + | Bytecode::UnpackVariant(_) + | Bytecode::UnpackVariantGeneric(_) + | Bytecode::UnpackVariantImmRef(_) + | Bytecode::UnpackVariantGenericImmRef(_) + | Bytecode::UnpackVariantMutRef(_) + | Bytecode::UnpackVariantGenericMutRef(_) + | Bytecode::VariantSwitch(_) => { + return Err( + PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) + .with_message("Unexpected variant opcode in version 1".to_string()), + ); + } }; Ok(()) } @@ -948,11 +961,11 @@ fn verify_instr( // Helpers functions for types // -fn materialize_type(struct_handle: StructHandleIndex, type_args: &Signature) -> SignatureToken { +fn materialize_type(struct_handle: DatatypeHandleIndex, type_args: &Signature) -> SignatureToken { if type_args.is_empty() { - ST::Struct(struct_handle) + ST::Datatype(struct_handle) } else { - ST::StructInstantiation(Box::new((struct_handle, type_args.0.clone()))) + ST::DatatypeInstantiation(Box::new((struct_handle, type_args.0.clone()))) } } @@ -974,10 +987,10 @@ fn instantiate(token: &SignatureToken, subst: &Signature) -> SignatureToken { Address => Address, Signer => Signer, Vector(ty) => Vector(Box::new(instantiate(ty, subst))), - Struct(idx) => Struct(*idx), - StructInstantiation(s) => { + Datatype(idx) => Datatype(*idx), + DatatypeInstantiation(s) => { let (idx, struct_type_args) = &**s; - StructInstantiation(Box::new(( + DatatypeInstantiation(Box::new(( *idx, struct_type_args .iter() diff --git a/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/interpreter.rs b/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/interpreter.rs index 2ed63fdd6cacb..83f1a53add32d 100644 --- a/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/interpreter.rs +++ b/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/interpreter.rs @@ -1271,6 +1271,15 @@ impl Frame { gas_meter.charge_vec_swap(make_ty!(ty))?; vec_ref.swap(idx1, idx2, ty)?; } + Bytecode::PackVariant(_) + | Bytecode::PackVariantGeneric(_) + | Bytecode::UnpackVariant(_) + | Bytecode::UnpackVariantGeneric(_) + | Bytecode::UnpackVariantImmRef(_) + | Bytecode::UnpackVariantMutRef(_) + | Bytecode::UnpackVariantGenericImmRef(_) + | Bytecode::UnpackVariantGenericMutRef(_) + | Bytecode::VariantSwitch(_) => unreachable!("enums not supported in V1"), } Ok(InstrRet::Ok) @@ -1400,7 +1409,7 @@ impl Frame { Type::Reference(ty) | Type::MutableReference(ty) | Type::Vector(ty) => { Self::check_depth_of_type_impl(resolver, ty, check_depth!(1), max_depth)? } - Type::Struct(si) => { + Type::Datatype(si) => { let struct_type = resolver.loader().get_struct_type(*si).ok_or_else(|| { PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) .with_message("Struct Definition not resolved".to_string()) @@ -1411,7 +1420,7 @@ impl Frame { .ok_or_else(|| { PartialVMError::new(StatusCode::VM_MAX_VALUE_DEPTH_REACHED) })? .solve(&[])?) } - Type::StructInstantiation(struct_inst) => { + Type::DatatypeInstantiation(struct_inst) => { let (si, ty_args) = &**struct_inst; // Calculate depth of all type arguments, and make sure they themselves are not too deep. let ty_arg_depths = ty_args diff --git a/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/loader.rs b/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/loader.rs index 22130429a3554..22729149f7687 100644 --- a/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/loader.rs +++ b/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/loader.rs @@ -32,7 +32,9 @@ use move_core_types::{ use move_vm_config::runtime::VMConfig; use move_vm_types::{ data_store::DataStore, - loaded_data::runtime_types::{CachedStructIndex, DepthFormula, StructType, Type}, + loaded_data::runtime_types::{ + CachedDatatype, CachedTypeIndex, Datatype, DepthFormula, StructType, Type, + }, }; use parking_lot::RwLock; use std::{ @@ -107,7 +109,7 @@ pub struct ModuleCache { loaded_modules: BinaryCache<(AccountAddress, ModuleId), LoadedModule>, /// Global cache of loaded structs, shared among all modules. - structs: BinaryCache<(ModuleId, Identifier), StructType>, + structs: BinaryCache<(ModuleId, Identifier), CachedDatatype>, /// Global list of loaded functions, shared among all modules. functions: Vec>, } @@ -158,7 +160,7 @@ impl ModuleCache { } // Retrieve a struct by index - fn struct_at(&self, idx: CachedStructIndex) -> Arc { + fn struct_at(&self, idx: CachedTypeIndex) -> Arc { Arc::clone(&self.structs.binaries[idx.0]) } @@ -221,7 +223,7 @@ impl ModuleCache { // Add new structs and collect their field signatures let mut field_signatures = vec![]; for (idx, struct_def) in module.struct_defs().iter().enumerate() { - let struct_handle = module.struct_handle_at(struct_def.struct_handle); + let struct_handle = module.datatype_handle_at(struct_def.struct_handle); let name = module.identifier_at(struct_handle.name); let struct_key = (runtime_id.clone(), name.to_owned()); @@ -241,16 +243,18 @@ impl ModuleCache { self.structs.insert( struct_key, - StructType { - fields: vec![], - field_names, + CachedDatatype { abilities: struct_handle.abilities, type_parameters: struct_handle.type_parameters.clone(), name: name.to_owned(), defining_id, runtime_id: runtime_id.clone(), - struct_def: StructDefinitionIndex(idx as u16), depth: None, + datatype_info: Datatype::Struct(StructType { + fields: vec![], + field_names, + struct_def: StructDefinitionIndex(idx as u16), + }), }, )?; @@ -283,7 +287,14 @@ impl ModuleCache { .zip(self.structs.binaries.iter_mut().rev()) { match Arc::get_mut(struct_type) { - Some(struct_type) => struct_type.fields = fields, + Some(ref mut x) => match &mut x.datatype_info { + Datatype::Enum(_) => { + unreachable!("enum types cannot be loaded into the cache in v0") + } + Datatype::Struct(ref mut struct_type) => { + struct_type.fields = fields; + } + }, None => { // we have pending references to the `Arc` which is impossible, // given the code that adds the `Arc` is above and no reference to @@ -292,8 +303,16 @@ impl ModuleCache { // over and log the issue. error!("Arc cannot have any live reference while publishing"); let mut struct_copy = (**struct_type).clone(); - struct_copy.fields = fields; - *struct_type = Arc::new(struct_copy); + match struct_copy.datatype_info { + Datatype::Enum(_) => { + unreachable!("enum types cannot be loaded into the cache in v0") + } + Datatype::Struct(ref mut s_info) => { + s_info.fields = fields; + struct_copy.datatype_info = Datatype::Struct(s_info.clone()); + *struct_type = Arc::new(struct_copy); + } + } } } } @@ -370,8 +389,8 @@ impl ModuleCache { SignatureToken::MutableReference(inner_tok) => { Type::MutableReference(Box::new(self.make_type(module, inner_tok)?)) } - SignatureToken::Struct(sh_idx) => { - let struct_handle = module.struct_handle_at(*sh_idx); + SignatureToken::Datatype(sh_idx) => { + let struct_handle = module.datatype_handle_at(*sh_idx); let struct_name = module.identifier_at(struct_handle.name); let module_handle = module.module_handle_at(struct_handle.module); let runtime_id = ModuleId::new( @@ -379,15 +398,15 @@ impl ModuleCache { module.identifier_at(module_handle.name).to_owned(), ); let def_idx = self.resolve_struct_by_name(struct_name, &runtime_id)?.0; - Type::Struct(def_idx) + Type::Datatype(def_idx) } - SignatureToken::StructInstantiation(struct_inst) => { + SignatureToken::DatatypeInstantiation(struct_inst) => { let (sh_idx, tys) = &**struct_inst; let type_parameters: Vec<_> = tys .iter() .map(|tok| self.make_type(module, tok)) .collect::>()?; - let struct_handle = module.struct_handle_at(*sh_idx); + let struct_handle = module.datatype_handle_at(*sh_idx); let struct_name = module.identifier_at(struct_handle.name); let module_handle = module.module_handle_at(struct_handle.module); let runtime_id = ModuleId::new( @@ -395,7 +414,7 @@ impl ModuleCache { module.identifier_at(module_handle.name).to_owned(), ); let def_idx = self.resolve_struct_by_name(struct_name, &runtime_id)?.0; - Type::StructInstantiation(Box::new((def_idx, type_parameters))) + Type::DatatypeInstantiation(Box::new((def_idx, type_parameters))) } }; Ok(res) @@ -403,8 +422,8 @@ impl ModuleCache { fn calculate_depth_of_struct( &self, - struct_type: &StructType, - depth_cache: &mut BTreeMap, + struct_type: &CachedDatatype, + depth_cache: &mut BTreeMap, ) -> PartialVMResult { let def_idx = self .resolve_struct_by_name(&struct_type.name, &struct_type.runtime_id)? @@ -418,11 +437,14 @@ impl ModuleCache { return Ok(form.clone()); } - let formulas = struct_type - .fields - .iter() - .map(|field_type| self.calculate_depth_of_type(field_type, depth_cache)) - .collect::>>()?; + let formulas = match &struct_type.datatype_info { + Datatype::Enum(_) => unreachable!("enum types cannot be loaded into the cache in v1"), + Datatype::Struct(s_info) => s_info + .fields + .iter() + .map(|field_type| self.calculate_depth_of_type(field_type, depth_cache)) + .collect::>>()?, + }; let mut formula = DepthFormula::normalize(formulas); // add 1 for the struct itself formula.add(1); @@ -439,7 +461,7 @@ impl ModuleCache { fn calculate_depth_of_type( &self, ty: &Type, - depth_cache: &mut BTreeMap, + depth_cache: &mut BTreeMap, ) -> PartialVMResult { Ok(match ty { Type::Bool @@ -459,13 +481,13 @@ impl ModuleCache { inner } Type::TyParam(ty_idx) => DepthFormula::type_parameter(*ty_idx), - Type::Struct(cache_idx) => { + Type::Datatype(cache_idx) => { let struct_type = self.struct_at(*cache_idx); let struct_formula = self.calculate_depth_of_struct(&struct_type, depth_cache)?; debug_assert!(struct_formula.terms.is_empty()); struct_formula } - Type::StructInstantiation(struct_inst) => { + Type::DatatypeInstantiation(struct_inst) => { let (cache_idx, ty_args) = &**struct_inst; let struct_type = self.struct_at(*cache_idx); let ty_arg_map = ty_args @@ -489,12 +511,12 @@ impl ModuleCache { &self, struct_name: &IdentStr, runtime_id: &ModuleId, - ) -> PartialVMResult<(CachedStructIndex, Arc)> { + ) -> PartialVMResult<(CachedTypeIndex, Arc)> { match self .structs .get_with_idx(&(runtime_id.clone(), struct_name.to_owned())) { - Some((idx, struct_)) => Ok((CachedStructIndex(idx), Arc::clone(struct_))), + Some((idx, struct_)) => Ok((CachedTypeIndex(idx), Arc::clone(struct_))), None => Err(PartialVMError::new(StatusCode::TYPE_RESOLUTION_FAILURE) .with_message(format!("Cannot find {runtime_id}::{struct_name} in cache",))), } @@ -802,7 +824,7 @@ impl Loader { name: &IdentStr, runtime_id: &ModuleId, data_store: &impl DataStore, - ) -> VMResult<(CachedStructIndex, Arc)> { + ) -> VMResult<(CachedTypeIndex, Arc)> { self.load_module(runtime_id, data_store)?; self.module_cache .read() @@ -832,7 +854,7 @@ impl Loader { let (idx, struct_type) = self.load_struct_by_name(&struct_tag.name, &runtime_id, data_store)?; if struct_type.type_parameters.is_empty() && struct_tag.type_params.is_empty() { - Type::Struct(idx) + Type::Datatype(idx) } else { let mut type_params = vec![]; for ty_param in &struct_tag.type_params { @@ -840,7 +862,7 @@ impl Loader { } self.verify_ty_args(struct_type.type_param_constraints(), &type_params) .map_err(|e| e.finish(Location::Undefined))?; - Type::StructInstantiation(Box::new((idx, type_params))) + Type::DatatypeInstantiation(Box::new((idx, type_params))) } } }) @@ -1120,7 +1142,7 @@ impl Loader { // existing type instantiation. // If that number is larger than MAX_TYPE_INSTANTIATION_NODES, refuse to construct this type. // This prevents constructing larger and lager types via struct instantiation. - if let Type::StructInstantiation(box_struct_inst) = ty { + if let Type::DatatypeInstantiation(box_struct_inst) = ty { let (_, struct_inst) = &**box_struct_inst; let mut sum_nodes = 1u64; for ty in ty_args.iter().chain(struct_inst.iter()) { @@ -1178,7 +1200,7 @@ impl Loader { (compiled, loaded) } - pub(crate) fn get_struct_type(&self, idx: CachedStructIndex) -> Option> { + pub(crate) fn get_struct_type(&self, idx: CachedTypeIndex) -> Option> { self.module_cache .read() .structs @@ -1211,8 +1233,8 @@ impl Loader { vec![false], vec![self.abilities(ty)?], ), - Type::Struct(idx) => Ok(self.module_cache.read().struct_at(*idx).abilities), - Type::StructInstantiation(struct_inst) => { + Type::Datatype(idx) => Ok(self.module_cache.read().struct_at(*idx).abilities), + Type::DatatypeInstantiation(struct_inst) => { let (idx, type_args) = &**struct_inst; let struct_type = self.module_cache.read().struct_at(*idx); let declared_phantom_parameters = struct_type @@ -1334,7 +1356,7 @@ impl<'a> Resolver<'a> { let struct_def = match &self.binary { BinaryType::Module { loaded, .. } => loaded.struct_at(idx), }; - Type::Struct(struct_def) + Type::Datatype(struct_def) } pub(crate) fn instantiate_generic_type( @@ -1358,7 +1380,7 @@ impl<'a> Resolver<'a> { } } - Ok(Type::StructInstantiation(Box::new(( + Ok(Type::DatatypeInstantiation(Box::new(( struct_inst.def, struct_inst .instantiation @@ -1454,10 +1476,10 @@ pub(crate) struct LoadedModule { // the instruction carries an index into this table which contains the index into the // glabal table of types. No instantiation of generic types is saved into the global table. #[allow(dead_code)] - struct_refs: Vec, + struct_refs: Vec, structs: Vec, // materialized instantiations, whether partial or not - struct_instantiations: Vec, + struct_instantiations: Vec, // functions as indexes into the Loader function list // That is effectively an indirection over the ref table: @@ -1504,7 +1526,7 @@ impl LoadedModule { let mut function_map = HashMap::new(); let mut single_signature_token_map = BTreeMap::new(); - for struct_handle in module.struct_handles() { + for struct_handle in module.datatype_handles() { let struct_name = module.identifier_at(struct_handle.name); let module_handle = module.module_handle_at(struct_handle.module); let runtime_id = module.module_id_for_handle(module_handle); @@ -1513,7 +1535,11 @@ impl LoadedModule { for struct_def in module.struct_defs() { let idx = struct_refs[struct_def.struct_handle.0 as usize]; - let field_count = cache.structs.binaries[idx.0].fields.len() as u16; + let field_count = cache.structs.binaries[idx.0] + .get_struct() + .unwrap() + .fields + .len() as u16; structs.push(StructDef { field_count, idx }); } @@ -1525,7 +1551,7 @@ impl LoadedModule { for ty in &module.signature_at(struct_inst.type_parameters).0 { instantiation.push(cache.make_type(module, ty)?); } - struct_instantiations.push(StructInstantiation { + struct_instantiations.push(DatatypeInstantiation { field_count, def: struct_def.idx, instantiation, @@ -1644,11 +1670,11 @@ impl LoadedModule { }) } - fn struct_at(&self, idx: StructDefinitionIndex) -> CachedStructIndex { + fn struct_at(&self, idx: StructDefinitionIndex) -> CachedTypeIndex { self.structs[idx.0 as usize].idx } - fn struct_instantiation_at(&self, idx: u16) -> &StructInstantiation { + fn struct_instantiation_at(&self, idx: u16) -> &DatatypeInstantiation { &self.struct_instantiations[idx as usize] } @@ -1875,15 +1901,15 @@ struct StructDef { // struct field count field_count: u16, // `ModuelCache::structs` global table index - idx: CachedStructIndex, + idx: CachedTypeIndex, } #[derive(Debug)] -struct StructInstantiation { +struct DatatypeInstantiation { // struct field count field_count: u16, // `ModuelCache::structs` global table index. It is the generic type. - def: CachedStructIndex, + def: CachedTypeIndex, instantiation: Vec, } @@ -1892,7 +1918,7 @@ struct StructInstantiation { struct FieldHandle { offset: usize, // `ModuelCache::structs` global table index. It is the generic type. - owner: CachedStructIndex, + owner: CachedTypeIndex, } // A field instantiation. The offset is the only used information when operating on a field @@ -1901,7 +1927,7 @@ struct FieldInstantiation { offset: usize, // `ModuelCache::structs` global table index. It is the generic type. #[allow(unused)] - owner: CachedStructIndex, + owner: CachedTypeIndex, } // @@ -1937,7 +1963,7 @@ impl StructInfo { } pub(crate) struct TypeCache { - structs: HashMap, StructInfo>>, + structs: HashMap, StructInfo>>, } impl TypeCache { @@ -1962,7 +1988,7 @@ const MAX_TYPE_INSTANTIATION_NODES: u64 = 128; impl Loader { fn read_cached_struct_tag( &self, - gidx: CachedStructIndex, + gidx: CachedTypeIndex, ty_args: &[Type], tag_type: StructTagType, ) -> Option { @@ -1978,7 +2004,7 @@ impl Loader { fn struct_gidx_to_type_tag( &self, - gidx: CachedStructIndex, + gidx: CachedTypeIndex, ty_args: &[Type], tag_type: StructTagType, ) -> PartialVMResult { @@ -2045,12 +2071,12 @@ impl Loader { Type::Vector(ty) => { TypeTag::Vector(Box::new(self.type_to_type_tag_impl(ty, tag_type)?)) } - Type::Struct(gidx) => TypeTag::Struct(Box::new(self.struct_gidx_to_type_tag( + Type::Datatype(gidx) => TypeTag::Struct(Box::new(self.struct_gidx_to_type_tag( *gidx, &[], tag_type, )?)), - Type::StructInstantiation(struct_inst) => { + Type::DatatypeInstantiation(struct_inst) => { let (gidx, ty_args) = &**struct_inst; TypeTag::Struct(Box::new( self.struct_gidx_to_type_tag(*gidx, ty_args, tag_type)?, @@ -2074,7 +2100,7 @@ impl Loader { result += 1; todo.push(ty); } - Type::StructInstantiation(struct_inst) => { + Type::DatatypeInstantiation(struct_inst) => { let (_, ty_args) = &**struct_inst; result += 1; todo.extend(ty_args.iter()) @@ -2089,7 +2115,7 @@ impl Loader { fn struct_gidx_to_type_layout( &self, - gidx: CachedStructIndex, + gidx: CachedTypeIndex, ty_args: &[Type], count: &mut u64, depth: u64, @@ -2108,6 +2134,8 @@ impl Loader { let count_before = *count; let struct_type = self.module_cache.read().struct_at(gidx); let field_tys = struct_type + .get_struct() + .unwrap() .fields .iter() .map(|ty| self.subst(ty, ty_args)) @@ -2159,13 +2187,13 @@ impl Loader { Type::Vector(ty) => R::MoveTypeLayout::Vector(Box::new( self.type_to_type_layout_impl(ty, count, depth + 1)?, )), - Type::Struct(gidx) => R::MoveTypeLayout::Struct(self.struct_gidx_to_type_layout( + Type::Datatype(gidx) => R::MoveTypeLayout::Struct(self.struct_gidx_to_type_layout( *gidx, &[], count, depth, )?), - Type::StructInstantiation(struct_inst) => { + Type::DatatypeInstantiation(struct_inst) => { let (gidx, ty_args) = &**struct_inst; R::MoveTypeLayout::Struct( self.struct_gidx_to_type_layout(*gidx, ty_args, count, depth)?, @@ -2182,7 +2210,7 @@ impl Loader { fn struct_gidx_to_fully_annotated_layout( &self, - gidx: CachedStructIndex, + gidx: CachedTypeIndex, ty_args: &[Type], count: &mut u64, depth: u64, @@ -2198,7 +2226,8 @@ impl Loader { } } - let struct_type = self.module_cache.read().struct_at(gidx); + let binding = self.module_cache.read().struct_at(gidx); + let struct_type = binding.get_struct().unwrap(); if struct_type.fields.len() != struct_type.field_names.len() { return Err( PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR).with_message( @@ -2261,10 +2290,10 @@ impl Loader { Type::Vector(ty) => A::MoveTypeLayout::Vector(Box::new( self.type_to_fully_annotated_layout_impl(ty, count, depth + 1)?, )), - Type::Struct(gidx) => A::MoveTypeLayout::Struct( + Type::Datatype(gidx) => A::MoveTypeLayout::Struct( self.struct_gidx_to_fully_annotated_layout(*gidx, &[], count, depth)?, ), - Type::StructInstantiation(struct_inst) => { + Type::DatatypeInstantiation(struct_inst) => { let (gidx, ty_args) = &**struct_inst; A::MoveTypeLayout::Struct( self.struct_gidx_to_fully_annotated_layout(*gidx, ty_args, count, depth)?, diff --git a/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/runtime.rs b/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/runtime.rs index 1670d1bae3d70..8a31ccd767942 100644 --- a/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/runtime.rs +++ b/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/runtime.rs @@ -30,7 +30,7 @@ use move_vm_config::runtime::VMConfig; use move_vm_types::{ data_store::DataStore, gas::GasMeter, - loaded_data::runtime_types::{CachedStructIndex, StructType, Type}, + loaded_data::runtime_types::{CachedTypeIndex, CachedDatatype, Type}, values::{Locals, Reference, VMValueCast, Value}, }; use std::{borrow::Borrow, collections::BTreeSet, sync::Arc}; @@ -458,7 +458,7 @@ impl VMRuntime { .map_err(|e| e.finish(Location::Undefined)) } - pub fn get_struct_type(&self, index: CachedStructIndex) -> Option> { + pub fn get_type(&self, index: CachedTypeIndex) -> Option> { self.loader.get_struct_type(index) } @@ -473,7 +473,7 @@ impl VMRuntime { module_id: &ModuleId, struct_name: &IdentStr, data_store: &impl DataStore, - ) -> VMResult<(CachedStructIndex, Arc)> { + ) -> VMResult<(CachedTypeIndex, Arc)> { self.loader .load_struct_by_name(struct_name, module_id, data_store) } diff --git a/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/session.rs b/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/session.rs index 02cdf62f84fc5..ba358b2a63c5c 100644 --- a/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/session.rs +++ b/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/session.rs @@ -22,7 +22,7 @@ use move_core_types::{ use move_vm_types::{ data_store::DataStore, gas::GasMeter, - loaded_data::runtime_types::{CachedStructIndex, StructType, Type}, + loaded_data::runtime_types::{CachedTypeIndex, CachedDatatype, Type}, }; use std::{borrow::Borrow, sync::Arc}; @@ -225,7 +225,7 @@ impl<'r, 'l, S: MoveResolver> Session<'r, 'l, S> { &self, module_id: &ModuleId, struct_name: &IdentStr, - ) -> VMResult<(CachedStructIndex, Arc)> { + ) -> VMResult<(CachedTypeIndex, Arc)> { self.runtime .loader() .load_struct_by_name(struct_name, module_id, &self.data_cache) @@ -273,7 +273,7 @@ impl<'r, 'l, S: MoveResolver> Session<'r, 'l, S> { /// Fetch a struct type from cache, if the index is in bounds /// Helpful when paired with load_type, or any other API that returns 'Type' - pub fn get_struct_type(&self, index: CachedStructIndex) -> Option> { + pub fn get_struct_type(&self, index: CachedTypeIndex) -> Option> { self.runtime.loader().get_struct_type(index) } diff --git a/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/unit_tests/vm_arguments_tests.rs b/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/unit_tests/vm_arguments_tests.rs index 8c3297675b176..abf424d8db730 100644 --- a/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/unit_tests/vm_arguments_tests.rs +++ b/external-crates/move/move-execution/v1/crates/move-vm-runtime/src/unit_tests/vm_arguments_tests.rs @@ -9,9 +9,9 @@ use move_binary_format::{ errors::{VMError, VMResult}, file_format::{ empty_module, AbilitySet, AddressIdentifierIndex, Bytecode, CodeUnit, CompiledModule, - FieldDefinition, FunctionDefinition, FunctionHandle, FunctionHandleIndex, IdentifierIndex, - ModuleHandle, ModuleHandleIndex, Signature, SignatureIndex, SignatureToken, - StructDefinition, StructFieldInformation, StructHandle, StructHandleIndex, TableIndex, + DatatypeHandle, DatatypeHandleIndex, FieldDefinition, FunctionDefinition, FunctionHandle, + FunctionHandleIndex, IdentifierIndex, ModuleHandle, ModuleHandleIndex, Signature, + SignatureIndex, SignatureToken, StructDefinition, StructFieldInformation, TableIndex, TypeSignature, Visibility, }, }; @@ -60,7 +60,7 @@ fn make_module_with_function( address: AddressIdentifierIndex(0), name: IdentifierIndex(0), }], - struct_handles: vec![StructHandle { + datatype_handles: vec![DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(1), abilities: AbilitySet::EMPTY, @@ -92,7 +92,7 @@ fn make_module_with_function( metadata: vec![], struct_defs: vec![StructDefinition { - struct_handle: StructHandleIndex(0), + struct_handle: DatatypeHandleIndex(0), field_information: StructFieldInformation::Declared(vec![FieldDefinition { name: IdentifierIndex(1), signature: TypeSignature(SignatureToken::Bool), @@ -106,8 +106,13 @@ fn make_module_with_function( code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::LdU64(0), Bytecode::Abort], + jump_tables: vec![], }), }], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; (module, function_name) } @@ -216,37 +221,37 @@ fn call_script_function( fn deprecated_bad_signatures() -> Vec { vec![ // struct in signature - Signature(vec![SignatureToken::Struct(StructHandleIndex(0))]), + Signature(vec![SignatureToken::Datatype(DatatypeHandleIndex(0))]), // struct in signature Signature(vec![ SignatureToken::Bool, - SignatureToken::Struct(StructHandleIndex(0)), + SignatureToken::Datatype(DatatypeHandleIndex(0)), SignatureToken::U64, ]), // reference to struct in signature Signature(vec![ SignatureToken::Address, - SignatureToken::MutableReference(Box::new(SignatureToken::Struct(StructHandleIndex( - 0, - )))), + SignatureToken::MutableReference(Box::new(SignatureToken::Datatype( + DatatypeHandleIndex(0), + ))), ]), // vector of struct in signature Signature(vec![ SignatureToken::Bool, - SignatureToken::Vector(Box::new(SignatureToken::Struct(StructHandleIndex(0)))), + SignatureToken::Vector(Box::new(SignatureToken::Datatype(DatatypeHandleIndex(0)))), SignatureToken::U64, ]), // vector of vector of struct in signature Signature(vec![ SignatureToken::Bool, SignatureToken::Vector(Box::new(SignatureToken::Vector(Box::new( - SignatureToken::Struct(StructHandleIndex(0)), + SignatureToken::Datatype(DatatypeHandleIndex(0)), )))), SignatureToken::U64, ]), // reference to vector in signature Signature(vec![SignatureToken::Reference(Box::new( - SignatureToken::Vector(Box::new(SignatureToken::Struct(StructHandleIndex(0)))), + SignatureToken::Vector(Box::new(SignatureToken::Datatype(DatatypeHandleIndex(0)))), ))]), // reference to vector in signature Signature(vec![SignatureToken::Reference(Box::new( diff --git a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.rs b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.rs index 905bc6540ba44..91bc085965a26 100644 --- a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.rs +++ b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.rs @@ -63,7 +63,7 @@ fn invalid_struct_in_fn_return_() { let mut m = basic_test_module(); m.function_handles[0].return_ = SignatureIndex(1); m.signatures - .push(Signature(vec![Struct(StructHandleIndex::new(1))])); + .push(Signature(vec![Datatype(DatatypeHandleIndex::new(1))])); assert_eq!( BoundsChecker::verify_module(&m).unwrap_err().major_status(), StatusCode::INDEX_OUT_OF_BOUNDS @@ -94,7 +94,7 @@ fn invalid_struct_in_field() { let mut m = basic_test_module(); match &mut m.struct_defs[0].field_information { StructFieldInformation::Declared(ref mut fields) => { - fields[0].signature.0 = Struct(StructHandleIndex::new(3)); + fields[0].signature.0 = Datatype(DatatypeHandleIndex::new(3)); assert_eq!( BoundsChecker::verify_module(&m).unwrap_err().major_status(), StatusCode::INDEX_OUT_OF_BOUNDS @@ -111,8 +111,8 @@ fn invalid_struct_with_actuals_in_field() { let mut m = basic_test_module(); match &mut m.struct_defs[0].field_information { StructFieldInformation::Declared(ref mut fields) => { - fields[0].signature.0 = StructInstantiation(Box::new(( - StructHandleIndex::new(0), + fields[0].signature.0 = DatatypeInstantiation(Box::new(( + DatatypeHandleIndex::new(0), vec![TypeParameter(0)], ))); assert_eq!( @@ -167,7 +167,7 @@ fn invalid_struct_as_type_actual_in_exists() { let mut m = basic_test_module(); m.signatures - .push(Signature(vec![Struct(StructHandleIndex::new(3))])); + .push(Signature(vec![Datatype(DatatypeHandleIndex::new(3))])); m.function_instantiations.push(FunctionInstantiation { handle: FunctionHandleIndex::new(0), type_parameters: SignatureIndex::new(1), @@ -239,7 +239,7 @@ fn invalid_struct_for_vector_operation() { let mut skeleton = basic_test_module(); skeleton .signatures - .push(Signature(vec![Struct(StructHandleIndex::new(3))])); + .push(Signature(vec![Datatype(DatatypeHandleIndex::new(3))])); let sig_index = SignatureIndex((skeleton.signatures.len() - 1) as u16); for bytecode in [ VecPack(sig_index, 0), diff --git a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/constants_tests.rs b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/constants_tests.rs index 653654119714d..239105833b302 100644 --- a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/constants_tests.rs +++ b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/constants_tests.rs @@ -238,7 +238,7 @@ fn invalid_types() { // TODO cannot check structs are banned currently. This can be handled by IR and source lang // tests - // invalid_type(SignatureToken::Struct(StructHandleIndex(0)), vec![0]); + // invalid_type(SignatureToken::Struct(DatatypeHandleIndex(0)), vec![0]); } fn tvec(s: SignatureToken) -> SignatureToken { diff --git a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/generic_ops_tests.rs b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/generic_ops_tests.rs index 92ab3aa12cba5..aec9fdbe19549 100644 --- a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/generic_ops_tests.rs +++ b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/generic_ops_tests.rs @@ -36,33 +36,33 @@ fn make_module() -> CompiledModule { address_identifiers: vec![ AccountAddress::ZERO, // Module address ], - struct_handles: vec![ - StructHandle { + datatype_handles: vec![ + DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(1), abilities: AbilitySet::PRIMITIVES, type_parameters: vec![], }, - StructHandle { + DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(2), abilities: AbilitySet::PRIMITIVES, - type_parameters: vec![StructTypeParameter { + type_parameters: vec![DatatypeTyParameter { constraints: AbilitySet::PRIMITIVES, is_phantom: false, }], }, - StructHandle { + DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(3), abilities: AbilitySet::EMPTY | Ability::Key, type_parameters: vec![], }, - StructHandle { + DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(4), abilities: AbilitySet::EMPTY | Ability::Key, - type_parameters: vec![StructTypeParameter { + type_parameters: vec![DatatypeTyParameter { constraints: AbilitySet::PRIMITIVES, is_phantom: false, }], @@ -71,7 +71,7 @@ fn make_module() -> CompiledModule { struct_defs: vec![ // struct S { f: u64 } StructDefinition { - struct_handle: StructHandleIndex(0), + struct_handle: DatatypeHandleIndex(0), field_information: StructFieldInformation::Declared(vec![FieldDefinition { name: IdentifierIndex(5), signature: TypeSignature(SignatureToken::U64), @@ -79,7 +79,7 @@ fn make_module() -> CompiledModule { }, // struct GS { f: T } StructDefinition { - struct_handle: StructHandleIndex(1), + struct_handle: DatatypeHandleIndex(1), field_information: StructFieldInformation::Declared(vec![FieldDefinition { name: IdentifierIndex(5), signature: TypeSignature(SignatureToken::TypeParameter(0)), @@ -87,7 +87,7 @@ fn make_module() -> CompiledModule { }, // struct R has key { f: u64 } StructDefinition { - struct_handle: StructHandleIndex(2), + struct_handle: DatatypeHandleIndex(2), field_information: StructFieldInformation::Declared(vec![FieldDefinition { name: IdentifierIndex(5), signature: TypeSignature(SignatureToken::U64), @@ -95,7 +95,7 @@ fn make_module() -> CompiledModule { }, // struct GR has key { f: T } StructDefinition { - struct_handle: StructHandleIndex(3), + struct_handle: DatatypeHandleIndex(3), field_information: StructFieldInformation::Declared(vec![FieldDefinition { name: IdentifierIndex(5), signature: TypeSignature(SignatureToken::TypeParameter(0)), @@ -138,6 +138,7 @@ fn make_module() -> CompiledModule { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Ret], + jump_tables: vec![], }), }, // fun g_fn() { return; } @@ -149,6 +150,7 @@ fn make_module() -> CompiledModule { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Ret], + jump_tables: vec![], }), }, // fun test_fn() { ... } - tests will fill up the code @@ -160,6 +162,7 @@ fn make_module() -> CompiledModule { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![], + jump_tables: vec![], }), }, ], @@ -180,6 +183,10 @@ fn make_module() -> CompiledModule { struct_def_instantiations: vec![], function_instantiations: vec![], field_instantiations: vec![], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], } } @@ -193,6 +200,7 @@ fn generic_call_to_non_generic_func() { Bytecode::CallGeneric(FunctionInstantiationIndex(0)), Bytecode::Ret, ], + jump_tables: vec![], }); module.function_instantiations.push(FunctionInstantiation { handle: FunctionHandleIndex(0), @@ -214,6 +222,7 @@ fn non_generic_call_to_generic_func() { module.function_defs[2].code = Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(1)), Bytecode::Ret], + jump_tables: vec![], }); let err = InstructionConsistency::verify_module(&module) .expect_err("Call to generic function must fail"); @@ -235,6 +244,7 @@ fn generic_pack_on_non_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module .struct_def_instantiations @@ -263,6 +273,7 @@ fn non_generic_pack_on_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); let err = InstructionConsistency::verify_module(&module) .expect_err("Pack to generic struct must fail"); @@ -285,6 +296,7 @@ fn generic_unpack_on_non_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module .struct_def_instantiations @@ -314,6 +326,7 @@ fn non_generic_unpack_on_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module .struct_def_instantiations @@ -343,6 +356,7 @@ fn generic_mut_borrow_field_on_non_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module.field_instantiations.push(FieldInstantiation { handle: FieldHandleIndex(0), @@ -374,6 +388,7 @@ fn non_generic_mut_borrow_field_on_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module .struct_def_instantiations @@ -407,6 +422,7 @@ fn generic_borrow_field_on_non_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module.field_instantiations.push(FieldInstantiation { handle: FieldHandleIndex(0), @@ -438,6 +454,7 @@ fn non_generic_borrow_field_on_generic_struct() { Bytecode::Pop, Bytecode::Ret, ], + jump_tables: vec![], }); module .struct_def_instantiations diff --git a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/large_type_test.rs b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/large_type_test.rs index 70953906af9bd..23b8c452d8915 100644 --- a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/large_type_test.rs +++ b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/large_type_test.rs @@ -48,6 +48,7 @@ fn test_large_types() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(0)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -68,6 +69,7 @@ fn test_large_types() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(1)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -89,6 +91,7 @@ fn test_large_types() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(1)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -109,6 +112,7 @@ fn test_large_types() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Ret], + jump_tables: vec![], }), }); @@ -131,6 +135,7 @@ fn test_large_types() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![], + jump_tables: vec![], }), }); diff --git a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/limit_tests.rs b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/limit_tests.rs index b30eaea22f91c..e7eda3d0ed084 100644 --- a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/limit_tests.rs +++ b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/limit_tests.rs @@ -38,11 +38,11 @@ fn test_function_handle_type_instantiation() { #[test] fn test_struct_handle_type_instantiation() { let mut m = basic_test_module(); - m.struct_handles.push(StructHandle { + m.datatype_handles.push(DatatypeHandle { module: ModuleHandleIndex::new(0), name: IdentifierIndex::new(0), abilities: AbilitySet::ALL, - type_parameters: std::iter::repeat(StructTypeParameter { + type_parameters: std::iter::repeat(DatatypeTyParameter { constraints: AbilitySet::ALL, is_phantom: false, }) @@ -97,7 +97,7 @@ fn big_vec_unpacks() { const N_TYPE_PARAMS: usize = 16; let mut st = SignatureToken::Vector(Box::new(SignatureToken::U8)); let type_params = vec![st; N_TYPE_PARAMS]; - st = SignatureToken::StructInstantiation(Box::new((StructHandleIndex(0), type_params))); + st = SignatureToken::DatatypeInstantiation(Box::new((DatatypeHandleIndex(0), type_params))); const N_VEC_PUSH: u16 = 1000; let mut code = vec![]; // 1. CopyLoc: ... -> ... st @@ -115,7 +115,7 @@ fn big_vec_unpacks() { code.push(Bytecode::Pop); } code.push(Bytecode::Ret); - let type_param_constraints = StructTypeParameter { + let type_param_constraints = DatatypeTyParameter { constraints: AbilitySet::EMPTY, is_phantom: false, }; @@ -126,7 +126,7 @@ fn big_vec_unpacks() { address: AddressIdentifierIndex(0), name: IdentifierIndex(0), }], - struct_handles: vec![StructHandle { + datatype_handles: vec![DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(1), abilities: AbilitySet::ALL, @@ -153,7 +153,7 @@ fn big_vec_unpacks() { constant_pool: vec![], metadata: vec![], struct_defs: vec![StructDefinition { - struct_handle: StructHandleIndex(0), + struct_handle: DatatypeHandleIndex(0), field_information: StructFieldInformation::Native, }], function_defs: vec![FunctionDefinition { @@ -164,8 +164,13 @@ fn big_vec_unpacks() { code: Some(CodeUnit { locals: SignatureIndex(0), code, + jump_tables: vec![], }), }], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; // save module and verify that it can ser/de @@ -199,7 +204,7 @@ const MAX_FUNCTIONS: usize = 1000; #[test] fn max_struct_test() { let config = VerifierConfig { - max_struct_definitions: Some(MAX_STRUCTS), + max_data_definitions: Some(MAX_STRUCTS), max_fields_in_struct: Some(MAX_FIELDS), max_function_definitions: Some(MAX_FUNCTIONS), ..Default::default() @@ -238,7 +243,7 @@ fn max_struct_test() { #[test] fn max_fields_test() { let config = VerifierConfig { - max_struct_definitions: Some(MAX_STRUCTS), + max_data_definitions: Some(MAX_STRUCTS), max_fields_in_struct: Some(MAX_FIELDS), max_function_definitions: Some(MAX_FUNCTIONS), ..Default::default() @@ -303,7 +308,7 @@ fn max_fields_test() { #[test] fn max_functions_test() { let config = VerifierConfig { - max_struct_definitions: Some(MAX_STRUCTS), + max_data_definitions: Some(MAX_STRUCTS), max_fields_in_struct: Some(MAX_FIELDS), max_function_definitions: Some(MAX_FUNCTIONS), ..Default::default() @@ -348,7 +353,7 @@ fn max_functions_test() { #[test] fn max_mixed_config_test() { let config = VerifierConfig { - max_struct_definitions: Some(MAX_STRUCTS), + max_data_definitions: Some(MAX_STRUCTS), max_fields_in_struct: Some(MAX_FIELDS), max_function_definitions: Some(MAX_FUNCTIONS), ..Default::default() @@ -362,7 +367,7 @@ fn max_mixed_config_test() { let config = VerifierConfig { max_function_definitions: None, - max_struct_definitions: None, + max_data_definitions: None, max_fields_in_struct: None, ..Default::default() }; @@ -392,7 +397,7 @@ fn max_mixed_config_test() { assert_eq!(res, Ok(())); let config = VerifierConfig { - max_struct_definitions: Some(MAX_STRUCTS), + max_data_definitions: Some(MAX_STRUCTS), max_fields_in_struct: Some(MAX_FIELDS), ..Default::default() }; @@ -434,7 +439,7 @@ fn max_mixed_config_test() { ); let config = VerifierConfig { - max_struct_definitions: Some(MAX_STRUCTS), + max_data_definitions: Some(MAX_STRUCTS), max_function_definitions: Some(MAX_FUNCTIONS), ..Default::default() }; @@ -739,14 +744,14 @@ fn multi_struct(module: &mut CompiledModule, count: usize) { module .identifiers .push(Identifier::new(format!("A_{}", i)).unwrap()); - module.struct_handles.push(StructHandle { + module.datatype_handles.push(DatatypeHandle { module: module.self_module_handle_idx, name: IdentifierIndex((module.identifiers.len() - 1) as u16), abilities: AbilitySet::EMPTY, type_parameters: vec![], }); module.struct_defs.push(StructDefinition { - struct_handle: StructHandleIndex((module.struct_handles.len() - 1) as u16), + struct_handle: DatatypeHandleIndex((module.datatype_handles.len() - 1) as u16), field_information: StructFieldInformation::Declared(vec![]), }); } @@ -806,6 +811,7 @@ fn multi_functions(module: &mut CompiledModule, count: usize) { code: Some(CodeUnit { locals: SignatureIndex((module.signatures.len() - 1) as u16), code: vec![Bytecode::Ret], + jump_tables: vec![], }), }); } diff --git a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/locals.rs b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/locals.rs index 6451e165a7232..c4e5a51558fe1 100644 --- a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/locals.rs +++ b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/locals.rs @@ -35,6 +35,7 @@ fn test_locals() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Ret], + jump_tables: vec![], }), }); @@ -67,6 +68,7 @@ fn test_locals() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::LdTrue, Bytecode::LdU8(0), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -89,6 +91,7 @@ fn test_locals() { code: Some(CodeUnit { locals: SignatureIndex(1), code: vec![], + jump_tables: vec![], }), }); diff --git a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/loop_summary_tests.rs b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/loop_summary_tests.rs index 819b9412709b9..a837f295ae398 100644 --- a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/loop_summary_tests.rs +++ b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/loop_summary_tests.rs @@ -23,13 +23,16 @@ macro_rules! assert_node { fn linear_summary() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ Nop, - /* */ Branch(2), - /* B2, L1 */ Nop, - /* */ Branch(4), - /* B4, L2 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ Nop, + /* */ Branch(2), + /* B2, L1 */ Nop, + /* */ Branch(4), + /* B4, L2 */ Ret, + ], + &[], + )) }; let n: Vec<_> = summary.preorder().collect(); @@ -65,12 +68,15 @@ fn linear_summary() { fn non_loop_back_branch_summary() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ Nop, - /* */ Branch(3), - /* B2, L2 */ Ret, - /* B3, L1 */ Branch(2), - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ Nop, + /* */ Branch(3), + /* B2, L2 */ Ret, + /* B3, L1 */ Branch(2), + ], + &[], + )) }; let n: Vec<_> = summary.preorder().collect(); @@ -106,12 +112,15 @@ fn non_loop_back_branch_summary() { fn branching_summary() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ LdTrue, - /* */ BrTrue(3), - /* B2, L2 */ Nop, - /* B3, L1 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ LdTrue, + /* */ BrTrue(3), + /* B2, L2 */ Nop, + /* B3, L1 */ Ret, + ], + &[], + )) }; let n: Vec<_> = summary.preorder().collect(); @@ -151,13 +160,16 @@ fn branching_summary() { fn looping_summary() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ LdTrue, - /* */ BrTrue(4), - /* B2, L2 */ Nop, - /* */ Branch(0), - /* B4, L1 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ LdTrue, + /* */ BrTrue(4), + /* B2, L2 */ Nop, + /* */ Branch(0), + /* B4, L1 */ Ret, + ], + &[], + )) }; let n: Vec<_> = summary.preorder().collect(); @@ -193,14 +205,17 @@ fn looping_summary() { fn branches_in_loops_summary() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ LdTrue, - /* */ BrTrue(3), - /* B2, L3 */ Nop, - /* B3, L1 */ LdFalse, - /* */ BrFalse(0), - /* B5, L2 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ LdTrue, + /* */ BrTrue(3), + /* B2, L3 */ Nop, + /* B3, L1 */ LdFalse, + /* */ BrFalse(0), + /* B5, L2 */ Ret, + ], + &[], + )) }; let n: Vec<_> = summary.preorder().collect(); @@ -244,22 +259,25 @@ fn branches_in_loops_summary() { fn loops_in_branches_summary() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ LdTrue, - /* */ BrTrue(8), - /* B2, L5 */ Nop, - /* B3, L6 */ LdFalse, - /* */ BrFalse(3), - /* B5, L7 */ LdTrue, - /* */ BrTrue(2), - /* B7, L8 */ Branch(13), - /* B8, L1 */ Nop, - /* B9, L2 */ LdTrue, - /* */ BrTrue(8), - /* B11, L3 */ LdFalse, - /* */ BrFalse(9), - /* B13, L4 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ LdTrue, + /* */ BrTrue(8), + /* B2, L5 */ Nop, + /* B3, L6 */ LdFalse, + /* */ BrFalse(3), + /* B5, L7 */ LdTrue, + /* */ BrTrue(2), + /* B7, L8 */ Branch(13), + /* B8, L1 */ Nop, + /* B9, L2 */ LdTrue, + /* */ BrTrue(8), + /* B11, L3 */ LdFalse, + /* */ BrFalse(9), + /* B13, L4 */ Ret, + ], + &[], + )) }; let n: Vec<_> = summary.preorder().collect(); @@ -343,13 +361,16 @@ fn loops_in_branches_summary() { fn loop_collapsing() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ LdTrue, - /* */ BrTrue(4), - /* B2, L2 */ Nop, - /* */ Branch(0), - /* B4, L1 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ LdTrue, + /* */ BrTrue(4), + /* B2, L2 */ Nop, + /* */ Branch(0), + /* B4, L1 */ Ret, + ], + &[], + )) }; let mut partition = LoopPartition::new(&summary); @@ -369,16 +390,19 @@ fn loop_collapsing() { fn nested_loop_collapsing() { let summary = { use Bytecode::*; - LoopSummary::new(&VMControlFlowGraph::new(&[ - /* B0, L0 */ Nop, - /* B1, L1 */ LdTrue, - /* */ BrTrue(1), - /* B3, L2 */ LdFalse, - /* */ BrFalse(0), - /* B5, L3 */ LdTrue, - /* */ BrTrue(0), - /* B7, L4 */ Ret, - ])) + LoopSummary::new(&VMControlFlowGraph::new( + &[ + /* B0, L0 */ Nop, + /* B1, L1 */ LdTrue, + /* */ BrTrue(1), + /* B3, L2 */ LdFalse, + /* */ BrFalse(0), + /* B5, L3 */ LdTrue, + /* */ BrTrue(0), + /* B7, L4 */ Ret, + ], + &[], + )) }; let mut partition = LoopPartition::new(&summary); diff --git a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/many_back_edges.rs b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/many_back_edges.rs index fe527fcbdf0f5..feda780b5cf93 100644 --- a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/many_back_edges.rs +++ b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/many_back_edges.rs @@ -46,6 +46,7 @@ fn many_backedges() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::LdTrue, Bytecode::LdU8(0), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -68,6 +69,7 @@ fn many_backedges() { code: Some(CodeUnit { locals: SignatureIndex(1), code: vec![], + jump_tables: vec![], }), }); diff --git a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/mod.rs b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/mod.rs index 3238641a6e76e..0ebd1d0fee366 100644 --- a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/mod.rs +++ b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/mod.rs @@ -2,6 +2,7 @@ // Copyright (c) The Move Contributors // SPDX-License-Identifier: Apache-2.0 +use move_core_types::VARIANT_COUNT_MAX; use move_vm_config::verifier::{ MeterConfig, VerifierConfig, DEFAULT_MAX_CONSTANT_VECTOR_LEN, DEFAULT_MAX_IDENTIFIER_LENGTH, }; @@ -36,7 +37,7 @@ pub(crate) fn production_config() -> (VerifierConfig, MeterConfig) { max_type_nodes: Some(256), max_push_size: Some(10000), max_dependency_depth: Some(100), - max_struct_definitions: Some(200), + max_data_definitions: Some(200), max_fields_in_struct: Some(30), max_function_definitions: Some(1000), @@ -48,6 +49,7 @@ pub(crate) fn production_config() -> (VerifierConfig, MeterConfig) { max_idenfitier_len: Some(DEFAULT_MAX_IDENTIFIER_LENGTH), allow_receiving_object_id: true, reject_mutable_random_on_entry_functions: true, + max_variants_in_enum: Some(VARIANT_COUNT_MAX), }, MeterConfig::default(), ) diff --git a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/reference_safety_tests.rs b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/reference_safety_tests.rs index 2fff034c142af..567364efe296c 100644 --- a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/reference_safety_tests.rs +++ b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/reference_safety_tests.rs @@ -35,6 +35,7 @@ fn test_bicliques() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(0)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -61,6 +62,7 @@ fn test_bicliques() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![], + jump_tables: vec![], }), }); let code = &mut m.function_defs[1].code.as_mut().unwrap().code; @@ -87,6 +89,7 @@ fn test_bicliques() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Ret], + jump_tables: vec![], }), }); @@ -109,6 +112,7 @@ fn test_bicliques() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![], + jump_tables: vec![], }), }); let code = &mut m.function_defs[i as usize + 2].code.as_mut().unwrap().code; @@ -160,6 +164,7 @@ fn test_merge_state_large_graph() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(0)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -185,6 +190,7 @@ fn test_merge_state_large_graph() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(1)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -205,6 +211,7 @@ fn test_merge_state_large_graph() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(1)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -226,6 +233,7 @@ fn test_merge_state_large_graph() { code: Some(CodeUnit { locals: SignatureIndex(1), code: vec![], + jump_tables: vec![], }), }); let code = &mut m.function_defs[i as usize + 3].code.as_mut().unwrap().code; @@ -282,6 +290,7 @@ fn test_merge_state() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::Call(FunctionHandleIndex(0)), Bytecode::Ret], + jump_tables: vec![], }), }); @@ -313,6 +322,7 @@ fn test_merge_state() { code: Some(CodeUnit { locals: SignatureIndex(2), code: vec![], + jump_tables: vec![], }), }); let code = &mut m.function_defs[i as usize + 1].code.as_mut().unwrap().code; @@ -395,6 +405,7 @@ fn test_copyloc_pop() { code: Some(CodeUnit { locals: SignatureIndex(2), code: vec![], + jump_tables: vec![], }), }); let code = &mut m.function_defs[i as usize].code.as_mut().unwrap().code; diff --git a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/signature_tests.rs b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/signature_tests.rs index 41d2d4e541081..2cfcc14aa176d 100644 --- a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/signature_tests.rs +++ b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/signature_tests.rs @@ -33,7 +33,7 @@ fn no_verify_locals_good() { name: IdentifierIndex(0), }], self_module_handle_idx: ModuleHandleIndex(0), - struct_handles: vec![], + datatype_handles: vec![], signatures: vec![ Signature(vec![Address]), Signature(vec![U64]), @@ -78,6 +78,7 @@ fn no_verify_locals_good() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Ret], + jump_tables: vec![], }), }, FunctionDefinition { @@ -88,9 +89,14 @@ fn no_verify_locals_good() { code: Some(CodeUnit { locals: SignatureIndex(1), code: vec![Ret], + jump_tables: vec![], }), }, ], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; assert!(verify_module_unmetered(&compiled_module_good).is_ok()); } @@ -106,7 +112,7 @@ fn big_signature_test() { } for _ in 0..INSTANTIATION_DEPTH { let type_params = vec![st; N_TYPE_PARAMS]; - st = SignatureToken::StructInstantiation(Box::new((StructHandleIndex(0), type_params))); + st = SignatureToken::DatatypeInstantiation(Box::new((DatatypeHandleIndex(0), type_params))); } const N_READPOP: u16 = 7500; @@ -122,7 +128,7 @@ fn big_signature_test() { } code.push(Bytecode::Ret); - let type_param_constraints = StructTypeParameter { + let type_param_constraints = DatatypeTyParameter { constraints: AbilitySet::EMPTY, is_phantom: false, }; @@ -134,7 +140,7 @@ fn big_signature_test() { address: AddressIdentifierIndex(0), name: IdentifierIndex(0), }], - struct_handles: vec![StructHandle { + datatype_handles: vec![DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(1), abilities: AbilitySet::ALL, @@ -161,7 +167,7 @@ fn big_signature_test() { constant_pool: vec![], metadata: vec![], struct_defs: vec![StructDefinition { - struct_handle: StructHandleIndex(0), + struct_handle: DatatypeHandleIndex(0), field_information: StructFieldInformation::Native, }], function_defs: vec![FunctionDefinition { @@ -172,8 +178,13 @@ fn big_signature_test() { code: Some(CodeUnit { locals: SignatureIndex(0), code, + jump_tables: vec![], }), }], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; // save module and verify that it can ser/de diff --git a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/vec_pack_tests.rs b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/vec_pack_tests.rs index 540962b3cbb24..96667cee33f04 100644 --- a/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/vec_pack_tests.rs +++ b/external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/vec_pack_tests.rs @@ -32,6 +32,7 @@ fn test_vec_pack() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![], + jump_tables: vec![], }), }); diff --git a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/ability_field_requirements.rs b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/ability_field_requirements.rs index e90c86efae4c5..5ef60518b65ae 100644 --- a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/ability_field_requirements.rs +++ b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/ability_field_requirements.rs @@ -17,7 +17,7 @@ pub fn verify_module(module: &CompiledModule) -> VMResult<()> { fn verify_module_impl(module: &CompiledModule) -> PartialVMResult<()> { for (idx, struct_def) in module.struct_defs().iter().enumerate() { - let sh = module.struct_handle_at(struct_def.struct_handle); + let sh = module.datatype_handle_at(struct_def.struct_handle); let fields = match &struct_def.field_information { StructFieldInformation::Native => continue, StructFieldInformation::Declared(fields) => fields, diff --git a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/absint.rs b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/absint.rs index 9f11fb5f7d37f..e9cad4ff0556b 100644 --- a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/absint.rs +++ b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/absint.rs @@ -194,7 +194,7 @@ impl<'a> FunctionContext<'a> { return_: module.signature_at(function_handle.return_), locals: module.signature_at(code.locals), type_parameters: &function_handle.type_parameters, - cfg: VMControlFlowGraph::new(&code.code), + cfg: VMControlFlowGraph::new(&code.code, &code.jump_tables), } } diff --git a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/acquires_list_verifier.rs b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/acquires_list_verifier.rs index cab0b6b9a6456..c49a7513f5295 100644 --- a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/acquires_list_verifier.rs +++ b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/acquires_list_verifier.rs @@ -72,7 +72,7 @@ impl<'a> AcquiresVerifier<'a> { } let struct_def = safe_unwrap!(module.struct_defs().get(annotation.0 as usize)); - let struct_handle = module.struct_handle_at(struct_def.struct_handle); + let struct_handle = module.datatype_handle_at(struct_def.struct_handle); if !struct_handle.abilities.has_key() { return Err(PartialVMError::new(StatusCode::INVALID_ACQUIRES_ANNOTATION)); } @@ -171,6 +171,18 @@ impl<'a> AcquiresVerifier<'a> { | Bytecode::VecPopBack(_) | Bytecode::VecUnpack(..) | Bytecode::VecSwap(_) => Ok(()), + Bytecode::PackVariant(_) + | Bytecode::PackVariantGeneric(_) + | Bytecode::UnpackVariant(_) + | Bytecode::UnpackVariantGeneric(_) + | Bytecode::UnpackVariantImmRef(_) + | Bytecode::UnpackVariantGenericImmRef(_) + | Bytecode::UnpackVariantMutRef(_) + | Bytecode::UnpackVariantGenericMutRef(_) + | Bytecode::VariantSwitch(_) => Err(PartialVMError::new( + StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR, + ) + .with_message("Unexpected variant opcode in version 2".to_string())), } } diff --git a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/check_duplication.rs b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/check_duplication.rs index 75b65f9d690b4..141ef3eca72b3 100644 --- a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/check_duplication.rs +++ b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/check_duplication.rs @@ -10,12 +10,11 @@ //! - the handles in struct and function definitions point to the self module index //! - all struct and function handles pointing to the self module index have a definition use move_binary_format::{ - errors::{verification_error, Location, PartialVMResult, VMResult}, file_format::{ - CompiledModule, Constant, FunctionHandle, FunctionHandleIndex, FunctionInstantiation, - ModuleHandle, Signature, StructFieldInformation, StructHandle, StructHandleIndex, - TableIndex, + CompiledModule, Constant, DatatypeHandle, DatatypeHandleIndex, FunctionHandle, + FunctionHandleIndex, FunctionInstantiation, ModuleHandle, Signature, + StructFieldInformation, TableIndex, }, IndexKind, }; @@ -40,7 +39,7 @@ impl<'a> DuplicationChecker<'a> { Self::check_signatures(module.signatures())?; Self::check_module_handles(module.module_handles())?; Self::check_module_handles(module.friend_decls())?; - Self::check_struct_handles(module.struct_handles())?; + Self::check_datatype_handles(module.datatype_handles())?; Self::check_function_handles(module.function_handles())?; Self::check_function_instantiations(module.function_instantiations())?; @@ -107,12 +106,12 @@ impl<'a> DuplicationChecker<'a> { } } - // StructHandles - module and name define uniqueness - fn check_struct_handles(struct_handles: &[StructHandle]) -> PartialVMResult<()> { - match Self::first_duplicate_element(struct_handles.iter().map(|x| (x.module, x.name))) { + // DatatypeHandles - module and name define uniqueness + fn check_datatype_handles(datatype_handles: &[DatatypeHandle]) -> PartialVMResult<()> { + match Self::first_duplicate_element(datatype_handles.iter().map(|x| (x.module, x.name))) { Some(idx) => Err(verification_error( StatusCode::DUPLICATE_ELEMENT, - IndexKind::StructHandle, + IndexKind::DatatypeHandle, idx, )), None => Ok(()), @@ -182,7 +181,7 @@ impl<'a> DuplicationChecker<'a> { } fn check_struct_definitions(&self) -> PartialVMResult<()> { - // StructDefinition - contained StructHandle defines uniqueness + // StructDefinition - contained DatatypeHandle defines uniqueness if let Some(idx) = Self::first_duplicate_element(self.module.struct_defs().iter().map(|x| x.struct_handle)) { @@ -215,7 +214,7 @@ impl<'a> DuplicationChecker<'a> { } // Check that each struct definition is pointing to the self module if let Some(idx) = self.module.struct_defs().iter().position(|x| { - self.module.struct_handle_at(x.struct_handle).module != self.module.self_handle_idx() + self.module.datatype_handle_at(x.struct_handle).module != self.module.self_handle_idx() }) { return Err(verification_error( StatusCode::INVALID_MODULE_HANDLE, @@ -224,20 +223,20 @@ impl<'a> DuplicationChecker<'a> { )); } // Check that each struct handle in self module is implemented (has a declaration) - let implemented_struct_handles: HashSet = self + let implemented_datatype_handles: HashSet = self .module .struct_defs() .iter() .map(|x| x.struct_handle) .collect(); - if let Some(idx) = (0..self.module.struct_handles().len()).position(|x| { - let y = StructHandleIndex::new(x as u16); - self.module.struct_handle_at(y).module == self.module.self_handle_idx() - && !implemented_struct_handles.contains(&y) + if let Some(idx) = (0..self.module.datatype_handles().len()).position(|x| { + let y = DatatypeHandleIndex::new(x as u16); + self.module.datatype_handle_at(y).module == self.module.self_handle_idx() + && !implemented_datatype_handles.contains(&y) }) { return Err(verification_error( StatusCode::UNIMPLEMENTED_HANDLE, - IndexKind::StructHandle, + IndexKind::DatatypeHandle, idx as TableIndex, )); } diff --git a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/dependencies.rs b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/dependencies.rs index 60a9e1c510acf..938a47337dbfc 100644 --- a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/dependencies.rs +++ b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/dependencies.rs @@ -6,9 +6,9 @@ use move_binary_format::{ errors::{verification_error, Location, PartialVMError, PartialVMResult, VMResult}, file_format::{ - AbilitySet, Bytecode, CodeOffset, CompiledModule, FunctionDefinitionIndex, - FunctionHandleIndex, ModuleHandleIndex, SignatureToken, StructHandleIndex, - StructTypeParameter, TableIndex, Visibility, + AbilitySet, Bytecode, CodeOffset, CompiledModule, DatatypeHandleIndex, DatatypeTyParameter, + FunctionDefinitionIndex, FunctionHandleIndex, ModuleHandleIndex, SignatureToken, + TableIndex, Visibility, }, file_format_common::VERSION_5, safe_unwrap, IndexKind, @@ -21,7 +21,7 @@ struct Context<'a, 'b> { // (Module -> CompiledModule) for (at least) all immediate dependencies dependency_map: BTreeMap, // (Module::StructName -> handle) for all types of all dependencies - struct_id_to_handle_map: BTreeMap<(ModuleId, Identifier), StructHandleIndex>, + struct_id_to_handle_map: BTreeMap<(ModuleId, Identifier), DatatypeHandleIndex>, // (Module::FunctionName -> handle) for all functions that can ever be called by this // module/script in all dependencies func_id_to_handle_map: BTreeMap<(ModuleId, Identifier), FunctionHandleIndex>, @@ -73,7 +73,7 @@ impl<'a, 'b> Context<'a, 'b> { // Module::StructName -> def handle idx for struct_def in module.struct_defs() { - let struct_handle = module.struct_handle_at(struct_def.struct_handle); + let struct_handle = module.datatype_handle_at(struct_def.struct_handle); let struct_name = module.identifier_at(struct_handle.name); context.struct_id_to_handle_map.insert( (module_id.clone(), struct_name.to_owned()), @@ -184,7 +184,7 @@ fn verify_imported_modules(context: &Context) -> PartialVMResult<()> { fn verify_imported_structs(context: &Context) -> PartialVMResult<()> { let self_module = context.resolver.self_handle_idx(); - for (idx, struct_handle) in context.resolver.struct_handles().iter().enumerate() { + for (idx, struct_handle) in context.resolver.datatype_handles().iter().enumerate() { if struct_handle.module == self_module { continue; } @@ -199,7 +199,7 @@ fn verify_imported_structs(context: &Context) -> PartialVMResult<()> { .get(&(owner_module_id, struct_name.to_owned())) { Some(def_idx) => { - let def_handle = owner_module.struct_handle_at(*def_idx); + let def_handle = owner_module.datatype_handle_at(*def_idx); if !compatible_struct_abilities(struct_handle.abilities, def_handle.abilities) || !compatible_struct_type_parameters( &struct_handle.type_parameters, @@ -208,7 +208,7 @@ fn verify_imported_structs(context: &Context) -> PartialVMResult<()> { { return Err(verification_error( StatusCode::TYPE_MISMATCH, - IndexKind::StructHandle, + IndexKind::DatatypeHandle, idx as TableIndex, )); } @@ -216,7 +216,7 @@ fn verify_imported_structs(context: &Context) -> PartialVMResult<()> { None => { return Err(verification_error( StatusCode::LOOKUP_FAILED, - IndexKind::StructHandle, + IndexKind::DatatypeHandle, idx as TableIndex, )) } @@ -345,8 +345,8 @@ fn compatible_fun_type_parameters( // - The number of type parameters must be the same // - Each pair of parameters must satisfy [`compatible_type_parameter_constraints`] and [`compatible_type_parameter_phantom_decl`] fn compatible_struct_type_parameters( - local_type_parameters_declaration: &[StructTypeParameter], - defined_type_parameters: &[StructTypeParameter], + local_type_parameters_declaration: &[DatatypeTyParameter], + defined_type_parameters: &[DatatypeTyParameter], ) -> bool { local_type_parameters_declaration.len() == defined_type_parameters.len() && local_type_parameters_declaration @@ -378,8 +378,8 @@ fn compatible_type_parameter_constraints( // Adding phantom declarations relaxes the requirements for clients, thus, the local view may // lack a phantom declaration present in the definition. fn compatible_type_parameter_phantom_decl( - local_type_parameter_declaration: &StructTypeParameter, - defined_type_parameter: &StructTypeParameter, + local_type_parameter_declaration: &DatatypeTyParameter, + defined_type_parameter: &DatatypeTyParameter, ) -> bool { // local_type_parameter_declaration.is_phantom => defined_type_parameter.is_phantom !local_type_parameter_declaration.is_phantom || defined_type_parameter.is_phantom @@ -419,12 +419,12 @@ fn compare_types( (SignatureToken::Vector(ty1), SignatureToken::Vector(ty2)) => { compare_types(context, ty1, ty2, def_module) } - (SignatureToken::Struct(idx1), SignatureToken::Struct(idx2)) => { + (SignatureToken::Datatype(idx1), SignatureToken::Datatype(idx2)) => { compare_structs(context, *idx1, *idx2, def_module) } ( - SignatureToken::StructInstantiation(struct_inst1), - SignatureToken::StructInstantiation(struct_inst2), + SignatureToken::DatatypeInstantiation(struct_inst1), + SignatureToken::DatatypeInstantiation(struct_inst2), ) => { let (idx1, inst1) = &**struct_inst1; let (idx2, inst2) = &**struct_inst2; @@ -449,8 +449,8 @@ fn compare_types( | (SignatureToken::Address, _) | (SignatureToken::Signer, _) | (SignatureToken::Vector(_), _) - | (SignatureToken::Struct(_), _) - | (SignatureToken::StructInstantiation(_), _) + | (SignatureToken::Datatype(_), _) + | (SignatureToken::DatatypeInstantiation(_), _) | (SignatureToken::Reference(_), _) | (SignatureToken::MutableReference(_), _) | (SignatureToken::TypeParameter(_), _) @@ -462,18 +462,18 @@ fn compare_types( fn compare_structs( context: &Context, - idx1: StructHandleIndex, - idx2: StructHandleIndex, + idx1: DatatypeHandleIndex, + idx2: DatatypeHandleIndex, def_module: &CompiledModule, ) -> PartialVMResult<()> { // grab ModuleId and struct name for the module being verified - let struct_handle = context.resolver.struct_handle_at(idx1); + let struct_handle = context.resolver.datatype_handle_at(idx1); let module_handle = context.resolver.module_handle_at(struct_handle.module); let module_id = context.resolver.module_id_for_handle(module_handle); let struct_name = context.resolver.identifier_at(struct_handle.name); // grab ModuleId and struct name for the definition - let def_struct_handle = def_module.struct_handle_at(idx2); + let def_struct_handle = def_module.datatype_handle_at(idx2); let def_module_handle = def_module.module_handle_at(def_struct_handle.module); let def_module_id = def_module.module_id_for_handle(def_module_handle); let def_struct_name = def_module.identifier_at(def_struct_handle.name); diff --git a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/instantiation_loops.rs b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/instantiation_loops.rs index ad7ed8ab20dd9..7c3dba2e5fbcf 100644 --- a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/instantiation_loops.rs +++ b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/instantiation_loops.rs @@ -142,13 +142,13 @@ impl<'a> InstantiationLoopChecker<'a> { fn rec(type_params: &mut HashSet, ty: &SignatureToken) { match ty { - Bool | Address | U8 | U16 | U32 | U64 | U128 | U256 | Signer | Struct(_) => (), + Bool | Address | U8 | U16 | U32 | U64 | U128 | U256 | Signer | Datatype(_) => (), TypeParameter(idx) => { type_params.insert(*idx); } Vector(ty) => rec(type_params, ty), Reference(ty) | MutableReference(ty) => rec(type_params, ty), - StructInstantiation(struct_inst) => { + DatatypeInstantiation(struct_inst) => { let (_, tys) = &**struct_inst; for ty in tys { rec(type_params, ty); diff --git a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/instruction_consistency.rs b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/instruction_consistency.rs index fc33c803f10e8..1e3e94f7b82a0 100644 --- a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/instruction_consistency.rs +++ b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/instruction_consistency.rs @@ -135,6 +135,21 @@ impl<'a> InstructionConsistency<'a> { | Or | And | Not | Eq | Neq | Lt | Gt | Le | Ge | CopyLoc(_) | MoveLoc(_) | StLoc(_) | MutBorrowLoc(_) | ImmBorrowLoc(_) | VecLen(_) | VecImmBorrow(_) | VecMutBorrow(_) | VecPushBack(_) | VecPopBack(_) | VecSwap(_) | Abort | Nop => (), + PackVariant(_) + | PackVariantGeneric(_) + | UnpackVariant(_) + | UnpackVariantGeneric(_) + | UnpackVariantImmRef(_) + | UnpackVariantGenericImmRef(_) + | UnpackVariantMutRef(_) + | UnpackVariantGenericMutRef(_) + | VariantSwitch(_) => { + return Err( + PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) + .at_code_offset(self.current_function(), offset as CodeOffset) + .with_message("Unexpected variant opcode in version 2".to_string()), + ); + } } } Ok(()) @@ -167,7 +182,7 @@ impl<'a> InstructionConsistency<'a> { generic: bool, ) -> PartialVMResult<()> { let struct_def = self.resolver.struct_def_at(struct_def_index); - let struct_handle = self.resolver.struct_handle_at(struct_def.struct_handle); + let struct_handle = self.resolver.datatype_handle_at(struct_def.struct_handle); if struct_handle.type_parameters.is_empty() == generic { return Err( PartialVMError::new(StatusCode::GENERIC_MEMBER_OPCODE_MISMATCH) diff --git a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/limits.rs b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/limits.rs index 90e92c8d7cd0f..312ff030b89d6 100644 --- a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/limits.rs +++ b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/limits.rs @@ -26,18 +26,18 @@ impl<'a> LimitsVerifier<'a> { let limit_check = Self { resolver: module }; limit_check.verify_constants(config)?; limit_check.verify_function_handles(config)?; - limit_check.verify_struct_handles(config)?; + limit_check.verify_datatype_handles(config)?; limit_check.verify_type_nodes(config)?; limit_check.verify_identifiers(config)?; limit_check.verify_definitions(config) } - fn verify_struct_handles(&self, config: &VerifierConfig) -> PartialVMResult<()> { + fn verify_datatype_handles(&self, config: &VerifierConfig) -> PartialVMResult<()> { if let Some(limit) = config.max_generic_instantiation_length { - for (idx, struct_handle) in self.resolver.struct_handles().iter().enumerate() { + for (idx, struct_handle) in self.resolver.datatype_handles().iter().enumerate() { if struct_handle.type_parameters.len() > limit { return Err(PartialVMError::new(StatusCode::TOO_MANY_TYPE_PARAMETERS) - .at_index(IndexKind::StructHandle, idx as u16)); + .at_index(IndexKind::DatatypeHandle, idx as u16)); } } } @@ -105,7 +105,7 @@ impl<'a> LimitsVerifier<'a> { // Notice that the preorder traversal will iterate all type instantiations, so we // why we can ignore them below. match t { - SignatureToken::Struct(..) | SignatureToken::StructInstantiation(..) => { + SignatureToken::Datatype(..) | SignatureToken::DatatypeInstantiation(..) => { size += STRUCT_SIZE_WEIGHT } SignatureToken::TypeParameter(..) => size += PARAM_SIZE_WEIGHT, @@ -132,7 +132,7 @@ impl<'a> LimitsVerifier<'a> { } let defs = self.resolver.struct_defs(); { - if let Some(max_struct_definitions) = config.max_struct_definitions { + if let Some(max_struct_definitions) = config.max_data_definitions { if defs.len() > max_struct_definitions { return Err(PartialVMError::new( StatusCode::MAX_STRUCT_DEFINITIONS_REACHED, diff --git a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/locals_safety/mod.rs b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/locals_safety/mod.rs index 1ffb24ed80074..c91fedb846ae0 100644 --- a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/locals_safety/mod.rs +++ b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/locals_safety/mod.rs @@ -160,6 +160,20 @@ fn execute_inner( | Bytecode::VecPopBack(_) | Bytecode::VecUnpack(..) | Bytecode::VecSwap(_) => (), + Bytecode::PackVariant(_) + | Bytecode::PackVariantGeneric(_) + | Bytecode::UnpackVariant(_) + | Bytecode::UnpackVariantGeneric(_) + | Bytecode::UnpackVariantImmRef(_) + | Bytecode::UnpackVariantGenericImmRef(_) + | Bytecode::UnpackVariantMutRef(_) + | Bytecode::UnpackVariantGenericMutRef(_) + | Bytecode::VariantSwitch(_) => { + return Err( + PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) + .with_message("Unexpected variant opcode in version 2".to_string()), + ); + } }; Ok(()) } diff --git a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/reference_safety/abstract_state.rs b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/reference_safety/abstract_state.rs index 66451e2146025..d8d7b9f00a9a9 100644 --- a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/reference_safety/abstract_state.rs +++ b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/reference_safety/abstract_state.rs @@ -440,7 +440,7 @@ impl AbstractState { if is_mut_borrow_with_full_borrows() || is_imm_borrow_with_mut_borrows() { // TODO improve error for mutable case - return Err(self.error(StatusCode::BORROWFIELD_EXISTS_MUTABLE_BORROW_ERROR, offset)); + return Err(self.error(StatusCode::FIELD_EXISTS_MUTABLE_BORROW_ERROR, offset)); } let field_borrow_id = self.new_ref(mut_); diff --git a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/reference_safety/mod.rs b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/reference_safety/mod.rs index 1f52c07f90d50..9132d823a14c6 100644 --- a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/reference_safety/mod.rs +++ b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/reference_safety/mod.rs @@ -425,6 +425,20 @@ fn execute_inner( let vec_ref = safe_unwrap_err!(verifier.stack.pop()); state.vector_op(offset, vec_ref, true)?; } + Bytecode::PackVariant(_) + | Bytecode::PackVariantGeneric(_) + | Bytecode::UnpackVariant(_) + | Bytecode::UnpackVariantGeneric(_) + | Bytecode::UnpackVariantImmRef(_) + | Bytecode::UnpackVariantGenericImmRef(_) + | Bytecode::UnpackVariantMutRef(_) + | Bytecode::UnpackVariantGenericMutRef(_) + | Bytecode::VariantSwitch(_) => { + return Err( + PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) + .with_message("Unexpected variant opcode in version 2".to_string()), + ); + } }; Ok(()) } diff --git a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/regression_tests/reference_analysis.rs b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/regression_tests/reference_analysis.rs index 2df2c7b43a5ed..51bd7d47db5c9 100644 --- a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/regression_tests/reference_analysis.rs +++ b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/regression_tests/reference_analysis.rs @@ -5,12 +5,11 @@ use move_binary_format::{ file_format::{ empty_module, AbilitySet, AddressIdentifierIndex, Bytecode::{self, *}, - CodeUnit, Constant, FieldDefinition, FunctionDefinition, FunctionHandle, - FunctionHandleIndex, IdentifierIndex, ModuleHandle, ModuleHandleIndex, Signature, - SignatureIndex, + CodeUnit, Constant, DatatypeHandle, DatatypeHandleIndex, FieldDefinition, + FunctionDefinition, FunctionHandle, FunctionHandleIndex, IdentifierIndex, ModuleHandle, + ModuleHandleIndex, Signature, SignatureIndex, SignatureToken::{self, *}, - StructDefinition, StructDefinitionIndex, StructFieldInformation, StructHandle, - StructHandleIndex, TypeSignature, Visibility, + StructDefinition, StructDefinitionIndex, StructFieldInformation, TypeSignature, Visibility, Visibility::*, }, CompiledModule, @@ -26,7 +25,7 @@ fn unbalanced_stack_crash() { let mut module = empty_module(); module.version = 5; - module.struct_handles.push(StructHandle { + module.datatype_handles.push(DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(1), abilities: AbilitySet::ALL, @@ -67,7 +66,7 @@ fn unbalanced_stack_crash() { }); module.struct_defs.push(StructDefinition { - struct_handle: StructHandleIndex(0), + struct_handle: DatatypeHandleIndex(0), field_information: StructFieldInformation::Declared(vec![FieldDefinition { name: IdentifierIndex::new(3), signature: TypeSignature(Address), @@ -92,6 +91,7 @@ fn unbalanced_stack_crash() { Ret, ], locals: SignatureIndex::new(2), + jump_tables: vec![], }; let fun_def = FunctionDefinition { code: Some(code_unit), @@ -125,7 +125,7 @@ fn too_many_locals() { address: AddressIdentifierIndex(0), name: IdentifierIndex(0), }], - struct_handles: vec![], + datatype_handles: vec![], function_handles: vec![FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), @@ -152,8 +152,13 @@ fn too_many_locals() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![CopyLoc(2), StLoc(33), Branch(0)], + jump_tables: vec![], }), }], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; let res = crate::verify_module_unmetered(&module); @@ -173,7 +178,7 @@ fn borrow_graph() { address: AddressIdentifierIndex(0), name: IdentifierIndex(0), }], - struct_handles: vec![], + datatype_handles: vec![], function_handles: vec![FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), @@ -203,8 +208,13 @@ fn borrow_graph() { code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![MoveLoc(0), MoveLoc(1), StLoc(0), StLoc(1), Branch(0)], + jump_tables: vec![], }), }], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; let res = crate::verify_module_unmetered(&module); @@ -269,7 +279,7 @@ fn indirect_code() { address: AddressIdentifierIndex(0), name: IdentifierIndex(0), }], - struct_handles: vec![], + datatype_handles: vec![], function_handles: vec![FunctionHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(0), @@ -307,8 +317,13 @@ fn indirect_code() { code: Some(CodeUnit { locals: SignatureIndex(1), code, + jump_tables: vec![], }), }], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; let res = crate::verify_module_with_config_unmetered(&VerifierConfig::default(), &module) diff --git a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/signature.rs b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/signature.rs index 29fb360a032a8..73cd6f1162f70 100644 --- a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/signature.rs +++ b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/signature.rs @@ -8,9 +8,9 @@ use move_binary_format::{ errors::{Location, PartialVMError, PartialVMResult, VMResult}, file_format::{ - AbilitySet, Bytecode, CodeUnit, CompiledModule, FunctionDefinition, FunctionHandle, - Signature, SignatureIndex, SignatureToken, StructDefinition, StructFieldInformation, - StructTypeParameter, TableIndex, + AbilitySet, Bytecode, CodeUnit, CompiledModule, DatatypeTyParameter, FunctionDefinition, + FunctionHandle, Signature, SignatureIndex, SignatureToken, StructDefinition, + StructFieldInformation, TableIndex, }, file_format_common::VERSION_6, IndexKind, @@ -71,7 +71,7 @@ impl<'a> SignatureChecker<'a> { StructFieldInformation::Native => continue, StructFieldInformation::Declared(fields) => fields, }; - let struct_handle = self.resolver.struct_handle_at(struct_def.struct_handle); + let struct_handle = self.resolver.datatype_handle_at(struct_def.struct_handle); let err_handler = |err: PartialVMError, idx| { err.at_index(IndexKind::FieldDefinition, idx as TableIndex) .at_index(IndexKind::StructDefinition, struct_def_idx as TableIndex) @@ -147,7 +147,7 @@ impl<'a> SignatureChecker<'a> { | MutBorrowGlobalGenericDeprecated(idx) => { let struct_inst = self.resolver.struct_instantiation_at(*idx); let struct_def = self.resolver.struct_def_at(struct_inst.def); - let struct_handle = self.resolver.struct_handle_at(struct_def.struct_handle); + let struct_handle = self.resolver.datatype_handle_at(struct_def.struct_handle); let type_arguments = &self.resolver.signature_at(struct_inst.type_parameters).0; self.check_signature_tokens(type_arguments)?; self.check_generic_instance( @@ -160,7 +160,7 @@ impl<'a> SignatureChecker<'a> { let field_inst = self.resolver.field_instantiation_at(*idx); let field_handle = self.resolver.field_handle_at(field_inst.handle); let struct_def = self.resolver.struct_def_at(field_handle.owner); - let struct_handle = self.resolver.struct_handle_at(struct_def.struct_handle); + let struct_handle = self.resolver.datatype_handle_at(struct_def.struct_handle); let type_arguments = &self.resolver.signature_at(field_inst.type_parameters).0; self.check_signature_tokens(type_arguments)?; self.check_generic_instance( @@ -251,6 +251,20 @@ impl<'a> SignatureChecker<'a> { | MoveFromDeprecated(_) | Abort | Nop => Ok(()), + PackVariant(_) + | PackVariantGeneric(_) + | UnpackVariant(_) + | UnpackVariantGeneric(_) + | UnpackVariantImmRef(_) + | UnpackVariantGenericImmRef(_) + | UnpackVariantMutRef(_) + | UnpackVariantGenericMutRef(_) + | VariantSwitch(_) => { + return Err( + PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) + .with_message("Unexpected variant opcode in version 0".to_string()), + ); + } }; result.map_err(|err| { err.append_message_with_separator(' ', format!("at offset {} ", offset)) @@ -264,13 +278,13 @@ impl<'a> SignatureChecker<'a> { &self, ty: &SignatureToken, is_phantom_pos: bool, - type_parameters: &[StructTypeParameter], + type_parameters: &[DatatypeTyParameter], ) -> PartialVMResult<()> { match ty { SignatureToken::Vector(ty) => self.check_phantom_params(ty, false, type_parameters)?, - SignatureToken::StructInstantiation(struct_inst) => { + SignatureToken::DatatypeInstantiation(struct_inst) => { let (idx, type_arguments) = &**struct_inst; - let sh = self.resolver.struct_handle_at(*idx); + let sh = self.resolver.datatype_handle_at(*idx); for (i, ty) in type_arguments.iter().enumerate() { self.check_phantom_params( ty, @@ -290,7 +304,7 @@ impl<'a> SignatureChecker<'a> { } } - SignatureToken::Struct(_) + SignatureToken::Datatype(_) | SignatureToken::Reference(_) | SignatureToken::MutableReference(_) | SignatureToken::Bool @@ -334,7 +348,7 @@ impl<'a> SignatureChecker<'a> { fn check_signature_token(&self, ty: &SignatureToken) -> PartialVMResult<()> { use SignatureToken::*; match ty { - U8 | U16 | U32 | U64 | U128 | U256 | Bool | Address | Signer | Struct(_) + U8 | U16 | U32 | U64 | U128 | U256 | Bool | Address | Signer | Datatype(_) | TypeParameter(_) => Ok(()), Reference(_) | MutableReference(_) => { // TODO: Prop tests expect us to NOT check the inner types. @@ -343,7 +357,7 @@ impl<'a> SignatureChecker<'a> { .with_message("reference not allowed".to_string())) } Vector(ty) => self.check_signature_token(ty), - StructInstantiation(struct_inst) => { + DatatypeInstantiation(struct_inst) => { let (_, type_arguments) = &**struct_inst; self.check_signature_tokens(type_arguments) } @@ -390,13 +404,13 @@ impl<'a> SignatureChecker<'a> { type_parameters: &[AbilitySet], ) -> PartialVMResult<()> { match s { - SignatureToken::StructInstantiation(struct_inst) => { + SignatureToken::DatatypeInstantiation(struct_inst) => { let (idx, type_arguments) = &**struct_inst; // Check that the instantiation satisfies the `idx` struct's constraints // Cannot be checked completely if we do not know the constraints of type parameters // i.e. it cannot be checked unless we are inside some module member. The only case // where that happens is when checking the signature pool itself - let sh = self.resolver.struct_handle_at(*idx); + let sh = self.resolver.datatype_handle_at(*idx); self.check_generic_instance( type_arguments, sh.type_param_constraints(), @@ -407,7 +421,7 @@ impl<'a> SignatureChecker<'a> { | SignatureToken::MutableReference(_) | SignatureToken::Vector(_) | SignatureToken::TypeParameter(_) - | SignatureToken::Struct(_) + | SignatureToken::Datatype(_) | SignatureToken::Bool | SignatureToken::U8 | SignatureToken::U16 diff --git a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/stack_usage_verifier.rs b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/stack_usage_verifier.rs index 1c3ee7db190f9..bbfaaa68e8755 100644 --- a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/stack_usage_verifier.rs +++ b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/stack_usage_verifier.rs @@ -265,6 +265,20 @@ impl<'a> StackUsageVerifier<'a> { }; (1, field_count as u64) } + Bytecode::PackVariant(_) + | Bytecode::PackVariantGeneric(_) + | Bytecode::UnpackVariant(_) + | Bytecode::UnpackVariantGeneric(_) + | Bytecode::UnpackVariantImmRef(_) + | Bytecode::UnpackVariantGenericImmRef(_) + | Bytecode::UnpackVariantMutRef(_) + | Bytecode::UnpackVariantGenericMutRef(_) + | Bytecode::VariantSwitch(_) => { + return Err( + PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) + .with_message("Unexpected variant opcode in version 2".to_string()), + ); + } }) } diff --git a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/struct_defs.rs b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/struct_defs.rs index 8db11769ab72b..8a8c88eb1a727 100644 --- a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/struct_defs.rs +++ b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/struct_defs.rs @@ -8,7 +8,7 @@ use move_binary_format::{ errors::{verification_error, Location, PartialVMError, PartialVMResult, VMResult}, file_format::{ - CompiledModule, SignatureToken, StructDefinitionIndex, StructHandleIndex, TableIndex, + CompiledModule, DatatypeHandleIndex, SignatureToken, StructDefinitionIndex, TableIndex, }, internals::ModuleIndex, IndexKind, @@ -35,7 +35,7 @@ impl<'a> RecursiveStructDefChecker<'a> { match toposort(&graph, None) { Ok(_) => Ok(()), Err(cycle) => Err(verification_error( - StatusCode::RECURSIVE_STRUCT_DEFINITION, + StatusCode::RECURSIVE_DATATYPE_DEFINITION, IndexKind::StructDefinition, cycle.node_id().into_index() as TableIndex, )), @@ -48,7 +48,7 @@ impl<'a> RecursiveStructDefChecker<'a> { struct StructDefGraphBuilder<'a> { module: &'a CompiledModule, /// Used to follow field definitions' signatures' struct handles to their struct definitions. - handle_to_def: BTreeMap, + handle_to_def: BTreeMap, } impl<'a> StructDefGraphBuilder<'a> { @@ -119,7 +119,7 @@ impl<'a> StructDefGraphBuilder<'a> { ) } T::Vector(inner) => self.add_signature_token(neighbors, cur_idx, inner)?, - T::Struct(sh_idx) => { + T::Datatype(sh_idx) => { if let Some(struct_def_idx) = self.handle_to_def.get(sh_idx) { neighbors .entry(cur_idx) @@ -127,7 +127,7 @@ impl<'a> StructDefGraphBuilder<'a> { .insert(*struct_def_idx); } } - T::StructInstantiation(struct_inst) => { + T::DatatypeInstantiation(struct_inst) => { let (sh_idx, inners) = &**struct_inst; if let Some(struct_def_idx) = self.handle_to_def.get(sh_idx) { neighbors diff --git a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/type_safety.rs b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/type_safety.rs index cd74b29ef12e9..580b53eb777e4 100644 --- a/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/type_safety.rs +++ b/external-crates/move/move-execution/v2/crates/move-bytecode-verifier/src/type_safety.rs @@ -13,12 +13,11 @@ use move_binary_format::{ control_flow_graph::ControlFlowGraph, errors::{PartialVMError, PartialVMResult}, file_format::{ - AbilitySet, Bytecode, CodeOffset, CompiledModule, FieldHandleIndex, + AbilitySet, Bytecode, CodeOffset, DatatypeHandleIndex, FieldHandleIndex, FunctionDefinitionIndex, FunctionHandle, LocalIndex, Signature, SignatureToken, SignatureToken as ST, StructDefinition, StructDefinitionIndex, StructFieldInformation, - StructHandleIndex, }, - safe_unwrap_err, + safe_unwrap_err, CompiledModule, }; use move_bytecode_verifier_meter::{Meter, Scope}; use move_core_types::vm_status::StatusCode; @@ -940,6 +939,20 @@ fn verify_instr( } verifier.push(meter, ST::U256)?; } + Bytecode::PackVariant(_) + | Bytecode::PackVariantGeneric(_) + | Bytecode::UnpackVariant(_) + | Bytecode::UnpackVariantGeneric(_) + | Bytecode::UnpackVariantImmRef(_) + | Bytecode::UnpackVariantGenericImmRef(_) + | Bytecode::UnpackVariantMutRef(_) + | Bytecode::UnpackVariantGenericMutRef(_) + | Bytecode::VariantSwitch(_) => { + return Err( + PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) + .with_message("Unexpected variant opcode in version 0".to_string()), + ); + } }; Ok(()) } @@ -948,11 +961,11 @@ fn verify_instr( // Helpers functions for types // -fn materialize_type(struct_handle: StructHandleIndex, type_args: &Signature) -> SignatureToken { +fn materialize_type(struct_handle: DatatypeHandleIndex, type_args: &Signature) -> SignatureToken { if type_args.is_empty() { - ST::Struct(struct_handle) + ST::Datatype(struct_handle) } else { - ST::StructInstantiation(Box::new((struct_handle, type_args.0.clone()))) + ST::DatatypeInstantiation(Box::new((struct_handle, type_args.0.clone()))) } } @@ -974,10 +987,10 @@ fn instantiate(token: &SignatureToken, subst: &Signature) -> SignatureToken { Address => Address, Signer => Signer, Vector(ty) => Vector(Box::new(instantiate(ty, subst))), - Struct(idx) => Struct(*idx), - StructInstantiation(struct_inst) => { + Datatype(idx) => Datatype(*idx), + DatatypeInstantiation(struct_inst) => { let (idx, struct_type_args) = &**struct_inst; - StructInstantiation(Box::new(( + DatatypeInstantiation(Box::new(( *idx, struct_type_args .iter() diff --git a/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/interpreter.rs b/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/interpreter.rs index 9b4a1476150e1..e5b8d95a8eab0 100644 --- a/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/interpreter.rs +++ b/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/interpreter.rs @@ -1272,6 +1272,15 @@ impl Frame { gas_meter.charge_vec_swap(make_ty!(ty))?; vec_ref.swap(idx1, idx2, ty)?; } + Bytecode::PackVariant(_) + | Bytecode::PackVariantGeneric(_) + | Bytecode::UnpackVariant(_) + | Bytecode::UnpackVariantGeneric(_) + | Bytecode::UnpackVariantImmRef(_) + | Bytecode::UnpackVariantMutRef(_) + | Bytecode::UnpackVariantGenericImmRef(_) + | Bytecode::UnpackVariantGenericMutRef(_) + | Bytecode::VariantSwitch(_) => unreachable!("enums not supported in V0"), } Ok(InstrRet::Ok) @@ -1400,7 +1409,7 @@ impl Frame { Type::Reference(ty) | Type::MutableReference(ty) | Type::Vector(ty) => { Self::check_depth_of_type_impl(resolver, ty, check_depth!(1), max_depth)? } - Type::Struct(si) => { + Type::Datatype(si) => { let struct_type = resolver.loader().get_struct_type(*si).ok_or_else(|| { PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) .with_message("Struct Definition not resolved".to_string()) @@ -1411,7 +1420,7 @@ impl Frame { .ok_or_else(|| { PartialVMError::new(StatusCode::VM_MAX_VALUE_DEPTH_REACHED) })? .solve(&[])?) } - Type::StructInstantiation(struct_inst) => { + Type::DatatypeInstantiation(struct_inst) => { let (si, ty_args) = &**struct_inst; // Calculate depth of all type arguments, and make sure they themselves are not too deep. let ty_arg_depths = ty_args diff --git a/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/loader.rs b/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/loader.rs index 2b7daff027fd2..edfa149e79c28 100644 --- a/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/loader.rs +++ b/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/loader.rs @@ -30,7 +30,9 @@ use move_core_types::{ use move_vm_config::runtime::VMConfig; use move_vm_types::{ data_store::DataStore, - loaded_data::runtime_types::{CachedStructIndex, DepthFormula, StructType, Type}, + loaded_data::runtime_types::{ + CachedDatatype, CachedTypeIndex, Datatype, DepthFormula, StructType, Type, + }, }; use parking_lot::RwLock; use std::{ @@ -105,7 +107,7 @@ pub struct ModuleCache { loaded_modules: BinaryCache<(AccountAddress, ModuleId), LoadedModule>, /// Global cache of loaded structs, shared among all modules. - structs: BinaryCache<(ModuleId, Identifier), StructType>, + structs: BinaryCache<(ModuleId, Identifier), CachedDatatype>, /// Global list of loaded functions, shared among all modules. functions: Vec>, } @@ -156,7 +158,7 @@ impl ModuleCache { } // Retrieve a struct by index - fn struct_at(&self, idx: CachedStructIndex) -> Arc { + fn struct_at(&self, idx: CachedTypeIndex) -> Arc { Arc::clone(&self.structs.binaries[idx.0]) } @@ -219,7 +221,7 @@ impl ModuleCache { // Add new structs and collect their field signatures let mut field_signatures = vec![]; for (idx, struct_def) in module.struct_defs().iter().enumerate() { - let struct_handle = module.struct_handle_at(struct_def.struct_handle); + let struct_handle = module.datatype_handle_at(struct_def.struct_handle); let name = module.identifier_at(struct_handle.name); let struct_key = (runtime_id.clone(), name.to_owned()); @@ -239,16 +241,18 @@ impl ModuleCache { self.structs.insert( struct_key, - StructType { - fields: vec![], - field_names, + CachedDatatype { abilities: struct_handle.abilities, type_parameters: struct_handle.type_parameters.clone(), name: name.to_owned(), defining_id, runtime_id: runtime_id.clone(), - struct_def: StructDefinitionIndex(idx as u16), depth: None, + datatype_info: Datatype::Struct(StructType { + fields: vec![], + field_names, + struct_def: StructDefinitionIndex(idx as u16), + }), }, )?; @@ -281,7 +285,14 @@ impl ModuleCache { .zip(self.structs.binaries.iter_mut().rev()) { match Arc::get_mut(struct_type) { - Some(struct_type) => struct_type.fields = fields, + Some(ref mut x) => match &mut x.datatype_info { + Datatype::Enum(_) => { + unreachable!("enum types cannot be loaded into the cache in v0") + } + Datatype::Struct(ref mut struct_type) => { + struct_type.fields = fields; + } + }, None => { // we have pending references to the `Arc` which is impossible, // given the code that adds the `Arc` is above and no reference to @@ -290,8 +301,16 @@ impl ModuleCache { // over and log the issue. error!("Arc cannot have any live reference while publishing"); let mut struct_copy = (**struct_type).clone(); - struct_copy.fields = fields; - *struct_type = Arc::new(struct_copy); + match struct_copy.datatype_info { + Datatype::Enum(_) => { + unreachable!("enum types cannot be loaded into the cache in v0") + } + Datatype::Struct(ref mut s_info) => { + s_info.fields = fields; + struct_copy.datatype_info = Datatype::Struct(s_info.clone()); + *struct_type = Arc::new(struct_copy); + } + } } } } @@ -350,8 +369,8 @@ impl ModuleCache { SignatureToken::MutableReference(inner_tok) => { Type::MutableReference(Box::new(self.make_type(module, inner_tok)?)) } - SignatureToken::Struct(sh_idx) => { - let struct_handle = module.struct_handle_at(*sh_idx); + SignatureToken::Datatype(sh_idx) => { + let struct_handle = module.datatype_handle_at(*sh_idx); let struct_name = module.identifier_at(struct_handle.name); let module_handle = module.module_handle_at(struct_handle.module); let runtime_id = ModuleId::new( @@ -359,15 +378,15 @@ impl ModuleCache { module.identifier_at(module_handle.name).to_owned(), ); let def_idx = self.resolve_struct_by_name(struct_name, &runtime_id)?.0; - Type::Struct(def_idx) + Type::Datatype(def_idx) } - SignatureToken::StructInstantiation(struct_inst) => { - let (sh_idx, tys) = &**struct_inst; + SignatureToken::DatatypeInstantiation(inst) => { + let (sh_idx, tys) = &**inst; let type_parameters: Vec<_> = tys .iter() .map(|tok| self.make_type(module, tok)) .collect::>()?; - let struct_handle = module.struct_handle_at(*sh_idx); + let struct_handle = module.datatype_handle_at(*sh_idx); let struct_name = module.identifier_at(struct_handle.name); let module_handle = module.module_handle_at(struct_handle.module); let runtime_id = ModuleId::new( @@ -375,7 +394,7 @@ impl ModuleCache { module.identifier_at(module_handle.name).to_owned(), ); let def_idx = self.resolve_struct_by_name(struct_name, &runtime_id)?.0; - Type::StructInstantiation(Box::new((def_idx, type_parameters))) + Type::DatatypeInstantiation(Box::new((def_idx, type_parameters))) } }; Ok(res) @@ -383,8 +402,8 @@ impl ModuleCache { fn calculate_depth_of_struct( &self, - struct_type: &StructType, - depth_cache: &mut BTreeMap, + struct_type: &CachedDatatype, + depth_cache: &mut BTreeMap, ) -> PartialVMResult { let def_idx = self .resolve_struct_by_name(&struct_type.name, &struct_type.runtime_id)? @@ -398,11 +417,14 @@ impl ModuleCache { return Ok(form.clone()); } - let formulas = struct_type - .fields - .iter() - .map(|field_type| self.calculate_depth_of_type(field_type, depth_cache)) - .collect::>>()?; + let formulas = match &struct_type.datatype_info { + Datatype::Enum(_) => unreachable!("enum types cannot be loaded into the cache in v0"), + Datatype::Struct(s_info) => s_info + .fields + .iter() + .map(|field_type| self.calculate_depth_of_type(field_type, depth_cache)) + .collect::>>()?, + }; let mut formula = DepthFormula::normalize(formulas); // add 1 for the struct itself formula.add(1); @@ -419,7 +441,7 @@ impl ModuleCache { fn calculate_depth_of_type( &self, ty: &Type, - depth_cache: &mut BTreeMap, + depth_cache: &mut BTreeMap, ) -> PartialVMResult { Ok(match ty { Type::Bool @@ -439,14 +461,14 @@ impl ModuleCache { inner } Type::TyParam(ty_idx) => DepthFormula::type_parameter(*ty_idx), - Type::Struct(cache_idx) => { + Type::Datatype(cache_idx) => { let struct_type = self.struct_at(*cache_idx); let struct_formula = self.calculate_depth_of_struct(&struct_type, depth_cache)?; debug_assert!(struct_formula.terms.is_empty()); struct_formula } - Type::StructInstantiation(struct_inst) => { - let (cache_idx, ty_args) = &**struct_inst; + Type::DatatypeInstantiation(inst) => { + let (cache_idx, ty_args) = &**inst; let struct_type = self.struct_at(*cache_idx); let ty_arg_map = ty_args .iter() @@ -469,12 +491,12 @@ impl ModuleCache { &self, struct_name: &IdentStr, runtime_id: &ModuleId, - ) -> PartialVMResult<(CachedStructIndex, Arc)> { + ) -> PartialVMResult<(CachedTypeIndex, Arc)> { match self .structs .get_with_idx(&(runtime_id.clone(), struct_name.to_owned())) { - Some((idx, struct_)) => Ok((CachedStructIndex(idx), Arc::clone(struct_))), + Some((idx, struct_)) => Ok((CachedTypeIndex(idx), Arc::clone(struct_))), None => Err(PartialVMError::new(StatusCode::TYPE_RESOLUTION_FAILURE) .with_message(format!("Cannot find {runtime_id}::{struct_name} in cache",))), } @@ -781,7 +803,7 @@ impl Loader { name: &IdentStr, runtime_id: &ModuleId, data_store: &impl DataStore, - ) -> VMResult<(CachedStructIndex, Arc)> { + ) -> VMResult<(CachedTypeIndex, Arc)> { self.load_module(runtime_id, data_store)?; self.module_cache .read() @@ -811,7 +833,7 @@ impl Loader { let (idx, struct_type) = self.load_struct_by_name(&struct_tag.name, &runtime_id, data_store)?; if struct_type.type_parameters.is_empty() && struct_tag.type_params.is_empty() { - Type::Struct(idx) + Type::Datatype(idx) } else { let mut type_params = vec![]; for ty_param in &struct_tag.type_params { @@ -819,7 +841,7 @@ impl Loader { } self.verify_ty_args(struct_type.type_param_constraints(), &type_params) .map_err(|e| e.finish(Location::Undefined))?; - Type::StructInstantiation(Box::new((idx, type_params))) + Type::DatatypeInstantiation(Box::new((idx, type_params))) } } }) @@ -1092,7 +1114,7 @@ impl Loader { // existing type instantiation. // If that number is larger than MAX_TYPE_INSTANTIATION_NODES, refuse to construct this type. // This prevents constructing larger and lager types via struct instantiation. - if let Type::StructInstantiation(box_struct_inst) = ty { + if let Type::DatatypeInstantiation(box_struct_inst) = ty { let (_, struct_inst) = &**box_struct_inst; let mut sum_nodes = 1u64; for ty in ty_args.iter().chain(struct_inst.iter()) { @@ -1149,7 +1171,7 @@ impl Loader { (compiled, loaded) } - pub(crate) fn get_struct_type(&self, idx: CachedStructIndex) -> Option> { + pub(crate) fn get_struct_type(&self, idx: CachedTypeIndex) -> Option> { self.module_cache .read() .structs @@ -1182,9 +1204,9 @@ impl Loader { vec![false], vec![self.abilities(ty)?], ), - Type::Struct(idx) => Ok(self.module_cache.read().struct_at(*idx).abilities), - Type::StructInstantiation(struct_inst) => { - let (idx, type_args) = &**struct_inst; + Type::Datatype(idx) => Ok(self.module_cache.read().struct_at(*idx).abilities), + Type::DatatypeInstantiation(inst) => { + let (idx, type_args) = &**inst; let struct_type = self.module_cache.read().struct_at(*idx); let declared_phantom_parameters = struct_type .type_parameters @@ -1288,7 +1310,7 @@ impl<'a> Resolver<'a> { pub(crate) fn get_struct_type(&self, idx: StructDefinitionIndex) -> Type { let struct_def = self.binary.loaded.struct_at(idx); - Type::Struct(struct_def) + Type::Datatype(struct_def) } pub(crate) fn instantiate_generic_type( @@ -1313,7 +1335,7 @@ impl<'a> Resolver<'a> { } } - Ok(Type::StructInstantiation(Box::new(( + Ok(Type::DatatypeInstantiation(Box::new(( struct_inst.def, instantiation .iter() @@ -1398,7 +1420,7 @@ pub(crate) struct LoadedModule { // the instruction carries an index into this table which contains the index into the // glabal table of types. No instantiation of generic types is saved into the global table. #[allow(dead_code)] - struct_refs: Vec, + struct_refs: Vec, structs: Vec, // materialized instantiations, whether partial or not struct_instantiations: Vec, @@ -1471,7 +1493,7 @@ impl LoadedModule { let mut function_map = HashMap::new(); let mut single_signature_token_map = BTreeMap::new(); - for struct_handle in module.struct_handles() { + for struct_handle in module.datatype_handles() { let struct_name = module.identifier_at(struct_handle.name); let module_handle = module.module_handle_at(struct_handle.module); let runtime_id = module.module_id_for_handle(module_handle); @@ -1480,7 +1502,11 @@ impl LoadedModule { for struct_def in module.struct_defs() { let idx = struct_refs[struct_def.struct_handle.0 as usize]; - let field_count = cache.structs.binaries[idx.0].fields.len() as u16; + let field_count = cache.structs.binaries[idx.0] + .get_struct() + .unwrap() + .fields + .len() as u16; structs.push(StructDef { field_count, idx }); } @@ -1617,7 +1643,7 @@ impl LoadedModule { }) } - fn struct_at(&self, idx: StructDefinitionIndex) -> CachedStructIndex { + fn struct_at(&self, idx: StructDefinitionIndex) -> CachedTypeIndex { self.structs[idx.0 as usize].idx } @@ -1845,16 +1871,16 @@ struct FunctionInstantiation { struct StructDef { // struct field count field_count: u16, - // `ModuleCache::structs` global table index - idx: CachedStructIndex, + // `ModuelCache::structs` global table index + idx: CachedTypeIndex, } #[derive(Debug)] struct StructInstantiation { // struct field count field_count: u16, - // `ModuleCache::structs` global table index. It is the generic type. - def: CachedStructIndex, + // `ModuelCache::structs` global table index. It is the generic type. + def: CachedTypeIndex, instantiation_idx: SignatureIndex, } @@ -1862,8 +1888,8 @@ struct StructInstantiation { #[derive(Debug)] struct FieldHandle { offset: usize, - // `ModuleCache::structs` global table index. It is the generic type. - owner: CachedStructIndex, + // `ModuelCache::structs` global table index. It is the generic type. + owner: CachedTypeIndex, } // A field instantiation. The offset is the only used information when operating on a field @@ -1872,7 +1898,7 @@ struct FieldInstantiation { offset: usize, // `ModuleCache::structs` global table index. It is the generic type. #[allow(unused)] - owner: CachedStructIndex, + owner: CachedTypeIndex, } // @@ -1908,7 +1934,7 @@ impl StructInfo { } pub(crate) struct TypeCache { - structs: HashMap, StructInfo>>, + structs: HashMap, StructInfo>>, } impl TypeCache { @@ -1933,7 +1959,7 @@ const MAX_TYPE_INSTANTIATION_NODES: u64 = 128; impl Loader { fn read_cached_struct_tag( &self, - gidx: CachedStructIndex, + gidx: CachedTypeIndex, ty_args: &[Type], tag_type: StructTagType, ) -> Option { @@ -1949,7 +1975,7 @@ impl Loader { fn struct_gidx_to_type_tag( &self, - gidx: CachedStructIndex, + gidx: CachedTypeIndex, ty_args: &[Type], tag_type: StructTagType, ) -> PartialVMResult { @@ -2016,13 +2042,13 @@ impl Loader { Type::Vector(ty) => { TypeTag::Vector(Box::new(self.type_to_type_tag_impl(ty, tag_type)?)) } - Type::Struct(gidx) => TypeTag::Struct(Box::new(self.struct_gidx_to_type_tag( + Type::Datatype(gidx) => TypeTag::Struct(Box::new(self.struct_gidx_to_type_tag( *gidx, &[], tag_type, )?)), - Type::StructInstantiation(struct_inst) => { - let (gidx, ty_args) = &**struct_inst; + Type::DatatypeInstantiation(inst) => { + let (gidx, ty_args) = &**inst; TypeTag::Struct(Box::new( self.struct_gidx_to_type_tag(*gidx, ty_args, tag_type)?, )) @@ -2045,8 +2071,8 @@ impl Loader { result += 1; todo.push(ty); } - Type::StructInstantiation(struct_inst) => { - let (_, ty_args) = &**struct_inst; + Type::DatatypeInstantiation(inst) => { + let (_, ty_args) = &**inst; result += 1; todo.extend(ty_args.iter()) } @@ -2060,7 +2086,7 @@ impl Loader { fn struct_gidx_to_type_layout( &self, - gidx: CachedStructIndex, + gidx: CachedTypeIndex, ty_args: &[Type], count: &mut u64, depth: u64, @@ -2077,7 +2103,8 @@ impl Loader { } let count_before = *count; - let struct_type = self.module_cache.read().struct_at(gidx); + let binding = self.module_cache.read().struct_at(gidx); + let struct_type = binding.get_struct().unwrap(); let field_tys = struct_type .fields .iter() @@ -2130,13 +2157,13 @@ impl Loader { Type::Vector(ty) => R::MoveTypeLayout::Vector(Box::new( self.type_to_type_layout_impl(ty, count, depth + 1)?, )), - Type::Struct(gidx) => R::MoveTypeLayout::Struct(self.struct_gidx_to_type_layout( + Type::Datatype(gidx) => R::MoveTypeLayout::Struct(self.struct_gidx_to_type_layout( *gidx, &[], count, depth, )?), - Type::StructInstantiation(struct_inst) => { + Type::DatatypeInstantiation(struct_inst) => { let (gidx, ty_args) = &**struct_inst; R::MoveTypeLayout::Struct( self.struct_gidx_to_type_layout(*gidx, ty_args, count, depth)?, @@ -2153,7 +2180,7 @@ impl Loader { fn struct_gidx_to_fully_annotated_layout( &self, - gidx: CachedStructIndex, + gidx: CachedTypeIndex, ty_args: &[Type], count: &mut u64, depth: u64, @@ -2169,7 +2196,8 @@ impl Loader { } } - let struct_type = self.module_cache.read().struct_at(gidx); + let binding = self.module_cache.read().struct_at(gidx); + let struct_type = binding.get_struct().unwrap(); if struct_type.fields.len() != struct_type.field_names.len() { return Err( PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR).with_message( @@ -2232,10 +2260,10 @@ impl Loader { Type::Vector(ty) => A::MoveTypeLayout::Vector(Box::new( self.type_to_fully_annotated_layout_impl(ty, count, depth + 1)?, )), - Type::Struct(gidx) => A::MoveTypeLayout::Struct( + Type::Datatype(gidx) => A::MoveTypeLayout::Struct( self.struct_gidx_to_fully_annotated_layout(*gidx, &[], count, depth)?, ), - Type::StructInstantiation(struct_inst) => { + Type::DatatypeInstantiation(struct_inst) => { let (gidx, ty_args) = &**struct_inst; A::MoveTypeLayout::Struct( self.struct_gidx_to_fully_annotated_layout(*gidx, ty_args, count, depth)?, diff --git a/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/runtime.rs b/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/runtime.rs index 400a2b6c9841e..5e416c6b80009 100644 --- a/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/runtime.rs +++ b/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/runtime.rs @@ -29,7 +29,7 @@ use move_vm_config::runtime::VMConfig; use move_vm_types::{ data_store::DataStore, gas::GasMeter, - loaded_data::runtime_types::{CachedStructIndex, StructType, Type}, + loaded_data::runtime_types::{CachedDatatype, CachedTypeIndex, Type}, values::{Locals, Reference, VMValueCast, Value}, }; use std::{borrow::Borrow, collections::BTreeSet, sync::Arc}; @@ -452,7 +452,7 @@ impl VMRuntime { .map_err(|e| e.finish(Location::Undefined)) } - pub fn get_struct_type(&self, index: CachedStructIndex) -> Option> { + pub fn get_struct_type(&self, index: CachedTypeIndex) -> Option> { self.loader.get_struct_type(index) } @@ -467,7 +467,7 @@ impl VMRuntime { module_id: &ModuleId, struct_name: &IdentStr, data_store: &impl DataStore, - ) -> VMResult<(CachedStructIndex, Arc)> { + ) -> VMResult<(CachedTypeIndex, Arc)> { self.loader .load_struct_by_name(struct_name, module_id, data_store) } diff --git a/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/session.rs b/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/session.rs index 02cdf62f84fc5..ba358b2a63c5c 100644 --- a/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/session.rs +++ b/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/session.rs @@ -22,7 +22,7 @@ use move_core_types::{ use move_vm_types::{ data_store::DataStore, gas::GasMeter, - loaded_data::runtime_types::{CachedStructIndex, StructType, Type}, + loaded_data::runtime_types::{CachedTypeIndex, CachedDatatype, Type}, }; use std::{borrow::Borrow, sync::Arc}; @@ -225,7 +225,7 @@ impl<'r, 'l, S: MoveResolver> Session<'r, 'l, S> { &self, module_id: &ModuleId, struct_name: &IdentStr, - ) -> VMResult<(CachedStructIndex, Arc)> { + ) -> VMResult<(CachedTypeIndex, Arc)> { self.runtime .loader() .load_struct_by_name(struct_name, module_id, &self.data_cache) @@ -273,7 +273,7 @@ impl<'r, 'l, S: MoveResolver> Session<'r, 'l, S> { /// Fetch a struct type from cache, if the index is in bounds /// Helpful when paired with load_type, or any other API that returns 'Type' - pub fn get_struct_type(&self, index: CachedStructIndex) -> Option> { + pub fn get_struct_type(&self, index: CachedTypeIndex) -> Option> { self.runtime.loader().get_struct_type(index) } diff --git a/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/unit_tests/vm_arguments_tests.rs b/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/unit_tests/vm_arguments_tests.rs index 8c3297675b176..abf424d8db730 100644 --- a/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/unit_tests/vm_arguments_tests.rs +++ b/external-crates/move/move-execution/v2/crates/move-vm-runtime/src/unit_tests/vm_arguments_tests.rs @@ -9,9 +9,9 @@ use move_binary_format::{ errors::{VMError, VMResult}, file_format::{ empty_module, AbilitySet, AddressIdentifierIndex, Bytecode, CodeUnit, CompiledModule, - FieldDefinition, FunctionDefinition, FunctionHandle, FunctionHandleIndex, IdentifierIndex, - ModuleHandle, ModuleHandleIndex, Signature, SignatureIndex, SignatureToken, - StructDefinition, StructFieldInformation, StructHandle, StructHandleIndex, TableIndex, + DatatypeHandle, DatatypeHandleIndex, FieldDefinition, FunctionDefinition, FunctionHandle, + FunctionHandleIndex, IdentifierIndex, ModuleHandle, ModuleHandleIndex, Signature, + SignatureIndex, SignatureToken, StructDefinition, StructFieldInformation, TableIndex, TypeSignature, Visibility, }, }; @@ -60,7 +60,7 @@ fn make_module_with_function( address: AddressIdentifierIndex(0), name: IdentifierIndex(0), }], - struct_handles: vec![StructHandle { + datatype_handles: vec![DatatypeHandle { module: ModuleHandleIndex(0), name: IdentifierIndex(1), abilities: AbilitySet::EMPTY, @@ -92,7 +92,7 @@ fn make_module_with_function( metadata: vec![], struct_defs: vec![StructDefinition { - struct_handle: StructHandleIndex(0), + struct_handle: DatatypeHandleIndex(0), field_information: StructFieldInformation::Declared(vec![FieldDefinition { name: IdentifierIndex(1), signature: TypeSignature(SignatureToken::Bool), @@ -106,8 +106,13 @@ fn make_module_with_function( code: Some(CodeUnit { locals: SignatureIndex(0), code: vec![Bytecode::LdU64(0), Bytecode::Abort], + jump_tables: vec![], }), }], + enum_defs: vec![], + enum_def_instantiations: vec![], + variant_handles: vec![], + variant_instantiation_handles: vec![], }; (module, function_name) } @@ -216,37 +221,37 @@ fn call_script_function( fn deprecated_bad_signatures() -> Vec { vec![ // struct in signature - Signature(vec![SignatureToken::Struct(StructHandleIndex(0))]), + Signature(vec![SignatureToken::Datatype(DatatypeHandleIndex(0))]), // struct in signature Signature(vec![ SignatureToken::Bool, - SignatureToken::Struct(StructHandleIndex(0)), + SignatureToken::Datatype(DatatypeHandleIndex(0)), SignatureToken::U64, ]), // reference to struct in signature Signature(vec![ SignatureToken::Address, - SignatureToken::MutableReference(Box::new(SignatureToken::Struct(StructHandleIndex( - 0, - )))), + SignatureToken::MutableReference(Box::new(SignatureToken::Datatype( + DatatypeHandleIndex(0), + ))), ]), // vector of struct in signature Signature(vec![ SignatureToken::Bool, - SignatureToken::Vector(Box::new(SignatureToken::Struct(StructHandleIndex(0)))), + SignatureToken::Vector(Box::new(SignatureToken::Datatype(DatatypeHandleIndex(0)))), SignatureToken::U64, ]), // vector of vector of struct in signature Signature(vec![ SignatureToken::Bool, SignatureToken::Vector(Box::new(SignatureToken::Vector(Box::new( - SignatureToken::Struct(StructHandleIndex(0)), + SignatureToken::Datatype(DatatypeHandleIndex(0)), )))), SignatureToken::U64, ]), // reference to vector in signature Signature(vec![SignatureToken::Reference(Box::new( - SignatureToken::Vector(Box::new(SignatureToken::Struct(StructHandleIndex(0)))), + SignatureToken::Vector(Box::new(SignatureToken::Datatype(DatatypeHandleIndex(0)))), ))]), // reference to vector in signature Signature(vec![SignatureToken::Reference(Box::new(