-
Notifications
You must be signed in to change notification settings - Fork 96
Closed as not planned
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
Milestone
Description
This PR introduces a design pattern. We can use this pattern to implement the type security in Move like borrow_global|move_from|move_to.
The PR introduces a new struct_tag module, but we can implement the pattern in the type_info module.
module moveos_std::type_info{
/// Returns the module authority for the TypeInfo of type `T`
public fun module_authority<T>(): TypeInfo {
let TypeInfo {
account_address,
module_name,
struct_name: _,
} = type_of<T>();
TypeInfo {
address_,
module_name,
struct_name: b"Witness",
}
}
}Then we can implement a public version of bcd::from_bytes
Current friend version:
moveos_std::bcd{
public(friend) native fun from_bytes<MoveValue>(bytes: vector<u8>): MoveValue;
}New public version:
module moveos_std::bcd{
public(friend) native fun internal_from_bytes<MoveValue>(bytes: vector<u8>): MoveValue;
public fun from_bytes<W,MoveValue>(witness: W, bytes: vector<u8>): MoveValue{
assert!(type_info::module_authority<MoveValue> == type_info::type_of<W>, ENO_MODULE_AUTHORITY);
internal_from_bytes(bytes)
}
}
module my_app:my_module{
struct Witness{}
struct MyResource{}
public fun new_from_bytes(bytes:&vector<u8>): MyResource{
bcd::from_bytes<Witness, MyResource>(Witness{}, bytes)
}
}
We also can use this method to resolve the #19 security issue.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
Type
Projects
Status
Done