Module bytecode

Module bytecode 

Source
Expand description

NeoVM Bytecode Generation Module

Converts the intermediate representation (IR) to NeoVM bytecode. This module handles the low-level emission of NeoVM opcodes and manages function dispatch, storage operations, and syscall generation.

ยงArchitecture

The bytecode generator works in several phases:

  1. Function dispatch - Generates entry point with method selector routing
  2. IR lowering - Converts IR instructions to NeoVM opcodes
  3. Optimization - Applies peephole optimizations to reduce bytecode size
  4. Patching - Resolves function call targets and jump addresses

ยงNeoVM Opcodes

Key opcodes used:

  • 0x00-0x20 - Push operations (PUSH0, PUSHINT8, etc.)
  • 0x40 - RET (return from function)
  • 0x41 - SYSCALL (invoke system call)
  • 0x45-0x4D - Control flow (JMP, JMPIF, CALL, etc.)

ยงStorage Model

Storage keys are computed using SHA-256 hashing of variable names and mapping keys, following Neo N3 storage conventions.

Structsยง

BytecodeBuildOutput ๐Ÿ”’
CallPatch ๐Ÿ”’
MethodTokenKey ๐Ÿ”’
MethodTokenPatch ๐Ÿ”’
StructArrayElementAccess ๐Ÿ”’
StructFieldAccess ๐Ÿ”’

Constantsยง

CALLFLAGS_ALL ๐Ÿ”’
Neo N3 uses CallFlags bitmask values.
CALLFLAGS_READ_ONLY ๐Ÿ”’
Read-only call flags (ReadStates | AllowCall).
NATIVE_CONTRACT_MANAGEMENT_HASH_LE ๐Ÿ”’
NATIVE_CRYPTOLIB_HASH_LE ๐Ÿ”’
NATIVE_GAS_HASH_LE ๐Ÿ”’
NATIVE_LEDGER_HASH_LE ๐Ÿ”’
NATIVE_NEO_HASH_LE ๐Ÿ”’
Native contract script hashes as they must be pushed onto the NeoVM stack (UInt160 little-endian byte order).
NATIVE_NOTARY_HASH_LE ๐Ÿ”’
NATIVE_ORACLE_HASH_LE ๐Ÿ”’
NATIVE_POLICY_HASH_LE ๐Ÿ”’
NATIVE_ROLE_MANAGEMENT_HASH_LE ๐Ÿ”’
NATIVE_STDLIB_HASH_LE ๐Ÿ”’
NATIVE_TREASURY_HASH_LE ๐Ÿ”’

Functionsยง

append_default_value ๐Ÿ”’
apply_method_tokens ๐Ÿ”’
disassemble_neovm_bytecode ๐Ÿ”’
emit_abi_decode ๐Ÿ”’
emit_abi_encode ๐Ÿ”’
emit_array_get ๐Ÿ”’
emit_array_set ๐Ÿ”’
emit_binary_op ๐Ÿ”’
emit_builtin_call ๐Ÿ”’
emit_coerce_storage_value ๐Ÿ”’
emit_contract_call ๐Ÿ”’
emit_contract_call_with_flags ๐Ÿ”’
emit_convert ๐Ÿ”’
emit_deploy_contract ๐Ÿ”’
emit_ecrecover ๐Ÿ”’
emit_event ๐Ÿ”’
emit_event_by_name ๐Ÿ”’
emit_event_payload ๐Ÿ”’
emit_get_contract ๐Ÿ”’
emit_get_contract_script ๐Ÿ”’
emit_get_neo_account_state ๐Ÿ”’
emit_ir_function ๐Ÿ”’
emit_is_type ๐Ÿ”’
emit_keccak256 ๐Ÿ”’
emit_load_local ๐Ÿ”’
emit_load_mapping ๐Ÿ”’
emit_load_parameter ๐Ÿ”’
emit_load_runtime_value ๐Ÿ”’
emit_load_state ๐Ÿ”’
emit_load_storage_dynamic ๐Ÿ”’
emit_load_struct_array_element ๐Ÿ”’
emit_load_struct_field ๐Ÿ”’
emit_load_struct_value_from_slot ๐Ÿ”’
emit_mapping_slot ๐Ÿ”’
emit_native_call ๐Ÿ”’
emit_native_contract_call ๐Ÿ”’
emit_new_array ๐Ÿ”’
emit_new_buffer ๐Ÿ”’
emit_notify_serialized ๐Ÿ”’
emit_runtime_check_witness ๐Ÿ”’
emit_runtime_notify ๐Ÿ”’
emit_serialize_key ๐Ÿ”’
emit_storage_delete ๐Ÿ”’
emit_storage_find ๐Ÿ”’
emit_storage_get ๐Ÿ”’
emit_storage_put ๐Ÿ”’
emit_store_local ๐Ÿ”’
emit_store_mapping ๐Ÿ”’
emit_store_state ๐Ÿ”’
emit_store_struct_array_element ๐Ÿ”’
emit_store_struct_field ๐Ÿ”’
emit_store_struct_value_to_slot ๐Ÿ”’
emit_struct_field_slot ๐Ÿ”’
emit_syscall ๐Ÿ”’
emit_syscall_builtin ๐Ÿ”’
emit_verify_signature ๐Ÿ”’
fmt_target ๐Ÿ”’
generate_contract_bytecode ๐Ÿ”’
is_void_syscall ๐Ÿ”’
native_contract_hash ๐Ÿ”’
native_method_call_flags ๐Ÿ”’
native_method_has_return_value ๐Ÿ”’
native_method_is_mutating ๐Ÿ”’
push_data ๐Ÿ”’
push_integer_bigint ๐Ÿ”’
push_literal_value ๐Ÿ”’
stack_item_type_code ๐Ÿ”’
take ๐Ÿ”’
take_i8 ๐Ÿ”’
take_i16 ๐Ÿ”’
take_i32 ๐Ÿ”’
take_i64 ๐Ÿ”’
take_u8 ๐Ÿ”’
take_u16 ๐Ÿ”’
take_u32 ๐Ÿ”’