Startup Process#
Standard library provides a built-in bootloader that bridges internal ABI to a more Pythonic interface.
Bootloader is located in module _genlayer_bootloader and is executed on import.
Bootloader Module#
_genlayer_bootloader handles contract execution in three distinct modes:
Entry Points#
The bootloader dispatches execution based on entry_kind from the VM message:
MAIN#
Handles standard contract method calls and initialization.
Loads user
contractmodule and resolves the target method of a declaredContractclassValidates method access permissions (public/private, payable)
Handles special methods:
__receive__,__handle_undefined_method__Routes initialization calls to
__init__methodEnforces security restrictions on dunder methods
SANDBOX#
Executes pickled function objects.
CONSENSUS_STAGE#
Runs consensus stage functions with additional stage data parameter (leader non-deterministic blocks outputs or None).
Method Resolution#
For MAIN entry kind, the bootloader implements comprehensive method resolution:
Initialization: Routes to private
__init__method during contract deploymentNamed Methods: Resolves public method calls by name with validation
Special Handling: Supports
__receive__for direct calls and__handle_undefined_method__for undefined method callsSecurity: Blocks calls to methods starting with
__and unknown special methods starting with#
Error Handling#
The bootloader provides centralized error management:
Catches
genlayer.gl.vm.UserErrorexceptions and triggers rollback with error messageValidates contract structure and method accessibility
Returns appropriate error messages for invalid method calls
Profiling Support#
Optional performance profiling when GENLAYER_ENABLE_PROFILER environment variable is set to true:
Uses
cProfilewith microsecond timing precisionOutputs compressed, base64-encoded statistics to stderr on exit
Integrates with GenVM debugging infrastructure
Storage Integration#
Manages contract storage lifecycle:
Locks default Storage Slots during contract initialization
Provides contract instance from the root slot