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 the 2 fallbacks for undefined nonempty method names, see Public, Payable and Special Methods
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: Rejects empty method names and routes other undefined methods to the fallbacks, see Public, Payable and Special Methods
Security: Blocks calls to methods starting with
__and unknown special methods starting with#
Error Handling#
The bootloader provides centralized error management:
Catches
genlayer.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