[−][src]Module solana_libra_vm::file_format
Binary format for transactions and modules.
This module provides a simple Rust abstraction over the binary format. That is the format of modules stored on chain or the format of the code section of a transaction.
file_format_common.rs
provides the constant values for entities in the binary format.
(The binary format is evolving so please come back here in time to check evolutions.)
Overall the binary format is structured in a number of sections:
- Header: this must start at offset 0 in the binary. It contains a blob that starts every Libra binary, followed by the version of the VM used to compile the code, and last is the number of tables present in this binary.
- Table Specification: it's a number of tuple of the form
(table type, starting_offset, byte_count)
. The number of entries is specified in the header (last entry in header). There can only be a single entry per table type. Thestarting offset
is from the beginning of the binary. Tables must cover the entire size of the binary blob and cannot overlap. - Table Content: the serialized form of the specific entries in the table. Those roughly map to the structs defined in this module. Entries in each table must be unique.
We have two formats: one for modules here represented by CompiledModule
, another
for transaction scripts which is CompiledScript
. Building those tables and passing them
to the serializer (serializer.rs
) generates a binary of the form described. Vectors in
those structs translate to tables and table specifications.
Structs
AddressPoolIndex | Index into the |
ByteArrayPoolIndex | Index into the |
CodeUnit | A |
CompiledModule | A |
CompiledModuleMut | A mutable version of |
CompiledProgram | A |
CompiledScript | Contains the main function to execute and its dependencies. |
CompiledScriptMut | A mutable version of |
FieldDefinition | A |
FieldDefinitionIndex | Index into the |
FunctionDefinition | A |
FunctionDefinitionIndex | Index into the |
FunctionHandle | A |
FunctionHandleIndex | Index into the |
FunctionSignature | A |
FunctionSignatureIndex | Index into the |
IdentifierIndex | Index into the |
LocalsSignature | A |
LocalsSignatureIndex | Index into the |
ModuleHandle | A |
ModuleHandleIndex | Index into the |
StructDefinition | A |
StructDefinitionIndex | Index into the |
StructHandle | A |
StructHandleIndex | Index into the |
TypeSignature | A type definition. |
TypeSignatureIndex | Index into the |
UserStringIndex | Index into the |
Enums
Bytecode |
|
Kind | A |
SignatureToken | A |
StructFieldInformation |
|
Constants
NO_TYPE_ACTUALS | Index 0 into the LocalsSignaturePool, which is guaranteed to be an empty list. Used to represent function/struct instantiation with no type actuals -- effectively non-generic functions and structs. |
NUMBER_OF_BYTECODE_INSTRUCTIONS | The number of bytecode instructions. This is necessary for checking that all instructions are covered since Rust does not provide a way of determining the number of variants of an enum. |
Functions
basic_test_module | Create the following module which is convenient in tests:
// module |
dummy_procedure_module | Create a dummy module to wrap the bytecode program in local@code |
empty_module | Return the simplest module that will pass the bounds checker |
self_module_name |
Type Definitions
AddressPool | The pool of |
ByteArrayPool | The pool of |
CodeOffset | Index into the code stream for a jump. The offset is relative to the beginning of the instruction stream. |
FunctionSignaturePool | The pool of |
IdentifierPool | The pool of identifiers. |
LocalIndex | Index of a local variable in a function. |
LocalsSignaturePool | The pool of |
MemberCount | Max number of fields in a |
TableIndex | Generic index into one of the tables in the binary format. |
TypeParameterIndex | Type parameters are encoded as indices. This index can also be used to lookup the kind of a
type parameter in the |
TypeSignaturePool | The pool of |
UserStringPool | The pool of string literals. |