util - [mainnet]
Utility functions used by the framework modules.
Functions
from_bytes
Native function to deserialize a type T.
Note that this function does not put any constraint on T
. If code uses this function to
deserialized a linear value, its their responsibility that the data they deserialize is
owned.
Function would abort if T has signer in it.
public(friend) fun from_bytes<T>(bytes: vector<u8>): T
Implementation
public(friend) native fun from_bytes<T>(bytes: vector<u8>): T;
address_from_bytes
public fun address_from_bytes(bytes: vector<u8>): address
Implementation
public fun address_from_bytes(bytes: vector<u8>): address { from_bytes(bytes)}
Specification
from_bytes
public(friend) fun from_bytes<T>(bytes: vector<u8>): T
High-level Requirements
No. | Requirement | Criticality | Implementation | Enforcement |
---|---|---|---|---|
1 | The address input bytes should be exactly 32 bytes long. | Low | The address_from_bytes function should assert if the length of the input bytes is 32. | Verified via address_from_bytes. |
Module-level Specification
pragma opaque;aborts_if [abstract] false;ensures [abstract] result == spec_from_bytes<T>(bytes);
fun spec_from_bytes<T>(bytes: vector<u8>): T;
address_from_bytes
public fun address_from_bytes(bytes: vector<u8>): address
// This enforces high-level requirement 1:aborts_if [abstract] len(bytes) != 32;