Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ENABLE_FUNCTION_VALUES feature flag and tests to show it is block…
Browse files Browse the repository at this point in the history
…ed by verifier. adding tests required serialization/desrialization of SignatureToken::Function.
brmataptos committed Dec 6, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 18a7dfa commit 844871b
Showing 17 changed files with 478 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -353,6 +353,7 @@ impl From<FeatureFlag> for AptosFeatureFlag {
FeatureFlag::CollectionOwner => AptosFeatureFlag::COLLECTION_OWNER,
FeatureFlag::NativeMemoryOperations => AptosFeatureFlag::NATIVE_MEMORY_OPERATIONS,
FeatureFlag::EnableLoaderV2 => AptosFeatureFlag::ENABLE_LOADER_V2,
FeatureFlag::EnableFunctionValues => AptosFeatureFlag::ENABLE_FUNCTION_VALUES,
}
}
}
@@ -500,6 +501,7 @@ impl From<AptosFeatureFlag> for FeatureFlag {
AptosFeatureFlag::COLLECTION_OWNER => FeatureFlag::CollectionOwner,
AptosFeatureFlag::NATIVE_MEMORY_OPERATIONS => FeatureFlag::NativeMemoryOperations,
AptosFeatureFlag::ENABLE_LOADER_V2 => FeatureFlag::EnableLoaderV2,
AptosFeatureFlag::ENABLE_FUNCTION_VALUES => FeatureFlag::EnableFunctionValues,
}
}
}
2 changes: 2 additions & 0 deletions aptos-move/aptos-vm-environment/src/prod_configs.rs
Original file line number Diff line number Diff line change
@@ -76,6 +76,7 @@ pub fn aptos_prod_verifier_config(features: &Features) -> VerifierConfig {
let enable_enum_types = features.is_enabled(FeatureFlag::ENABLE_ENUM_TYPES);
let enable_resource_access_control =
features.is_enabled(FeatureFlag::ENABLE_RESOURCE_ACCESS_CONTROL);
let enable_function_values = features.is_enabled(FeatureFlag::ENABLE_FUNCTION_VALUES);

VerifierConfig {
max_loop_depth: Some(5),
@@ -98,6 +99,7 @@ pub fn aptos_prod_verifier_config(features: &Features) -> VerifierConfig {
sig_checker_v2_fix_script_ty_param_count,
enable_enum_types,
enable_resource_access_control,
enable_function_values,
}
}

9 changes: 9 additions & 0 deletions aptos-move/framework/src/built_package.rs
Original file line number Diff line number Diff line change
@@ -149,6 +149,15 @@ impl BuildOptions {
}
}

pub fn move_2_2() -> Self {
BuildOptions {
bytecode_version: Some(VERSION_7),
language_version: Some(LanguageVersion::V2_2),
compiler_version: Some(CompilerVersion::latest_stable()),
..Self::default()
}
}

pub fn inferred_bytecode_version(&self) -> u32 {
self.language_version
.unwrap_or_default()
64 changes: 63 additions & 1 deletion third_party/move/move-binary-format/src/deserializer.rs
Original file line number Diff line number Diff line change
@@ -1137,6 +1137,13 @@ fn load_signature_token(cursor: &mut VersionedCursor) -> BinaryLoaderResult<Sign
arity: usize,
ty_args: Vec<SignatureToken>,
},
Function {
args_arity: u64,
res_arity: u64,
args: Vec<SignatureToken>,
results: Vec<SignatureToken>,
abilities: AbilitySet,
},
}

impl TypeBuilder {
@@ -1163,6 +1170,41 @@ fn load_signature_token(cursor: &mut VersionedCursor) -> BinaryLoaderResult<Sign
}
}
},
T::Function {
args_arity,
res_arity,
mut args,
mut results,
abilities,
} => {
if args.len() >= args_arity as usize {
results.push(tok);
if results.len() >= res_arity as usize {
T::Saturated(SignatureToken::Function {
args,
results,
abilities,
})
} else {
T::Function {
args_arity,
res_arity,
args,
results,
abilities,
}
}
} else {
args.push(tok);
T::Function {
args_arity,
res_arity,
args,
results,
abilities,
}
}
},
_ => unreachable!("invalid type constructor application"),
}
}
@@ -1229,6 +1271,19 @@ fn load_signature_token(cursor: &mut VersionedCursor) -> BinaryLoaderResult<Sign
let idx = load_type_parameter_index(cursor)?;
T::Saturated(SignatureToken::TypeParameter(idx))
},
S::FUNCTION => {
let args_arity = load_signature_size(cursor)?;
let res_arity = load_signature_size(cursor)?;
let abilities =
load_ability_set(cursor, AbilitySetPosition::FunctionValueType)?;
T::Function {
args_arity,
res_arity,
abilities,
args: vec![],
results: vec![],
}
},
})
} else {
Err(PartialVMError::new(StatusCode::MALFORMED)
@@ -1263,6 +1318,7 @@ enum AbilitySetPosition {
FunctionTypeParameters,
StructTypeParameters,
StructHandle,
FunctionValueType,
}

fn load_ability_set(
@@ -1312,11 +1368,17 @@ fn load_ability_set(
DeprecatedKind::RESOURCE => AbilitySet::EMPTY | Ability::Key,
};
Ok(match pos {
AbilitySetPosition::StructHandle => unreachable!(),
AbilitySetPosition::StructHandle | AbilitySetPosition::FunctionValueType => {
unreachable!()
},
AbilitySetPosition::FunctionTypeParameters => set | Ability::Store,
AbilitySetPosition::StructTypeParameters => set,
})
},
AbilitySetPosition::FunctionValueType => {
// This is a new type, shouldn't show up here.
Err(PartialVMError::new(StatusCode::UNKNOWN_ABILITY))
},
}
} else {
// The uleb here doesn't really do anything as it is bounded currently to 0xF, but the
1 change: 1 addition & 0 deletions third_party/move/move-binary-format/src/file_format.rs
Original file line number Diff line number Diff line change
@@ -1246,6 +1246,7 @@ pub enum AddressSpecifier {
feature = "fuzzing",
derive(arbitrary::Arbitrary, dearbitrary::Dearbitrary)
)]
#[allow(unused_variables)]
pub enum SignatureToken {
/// Boolean, `true` or `false`.
Bool,
Original file line number Diff line number Diff line change
@@ -140,6 +140,7 @@ pub enum SerializedType {
U16 = 0xD,
U32 = 0xE,
U256 = 0xF,
FUNCTION = 0x10,
}

/// A marker for an option in the serialized output.
11 changes: 9 additions & 2 deletions third_party/move/move-binary-format/src/serializer.rs
Original file line number Diff line number Diff line change
@@ -800,8 +800,15 @@ fn serialize_signature_token_single_node_impl(
binary.push(SerializedType::TYPE_PARAMETER as u8)?;
serialize_type_parameter_index(binary, *idx)?;
},
SignatureToken::Function { .. } => {
unimplemented!("serialization of function types")
SignatureToken::Function {
args,
results,
abilities,
} => {
binary.push(SerializedType::FUNCTION as u8)?;
serialize_signature_size(binary, args.len())?;
serialize_signature_size(binary, results.len())?;
serialize_ability_set(binary, *abilities)?;
},
}
Ok(())
Loading

0 comments on commit 844871b

Please sign in to comment.