Skip to content

Add module import validation and configurable failure handling#284

Draft
wbssbw wants to merge 4 commits intoobelisk:mainfrom
wbssbw:loading/check-module-imports
Draft

Add module import validation and configurable failure handling#284
wbssbw wants to merge 4 commits intoobelisk:mainfrom
wbssbw:loading/check-module-imports

Conversation

@wbssbw
Copy link
Collaborator

@wbssbw wbssbw commented Mar 13, 2026

Summary

This change enhances module loading safety and configurability by validating module imports at compile time and adding configurable behavior for handling various failure modes. The API function registration code was also refactored using a declarative macro to reduce boilerplate and improve maintainability.

Changes

Code refactoring:

  • Refactored API function registration in runtime/plaid/src/functions/api.rs using a new define_api_functions! macro that generates both the function registration logic and a lookup function
  • Exported is_known_api_function from the functions module for use in module validation

Module loading improvements:

  • Added import validation during module compilation to check that every function imported by a WASM module exists in the host API
  • Returns a MissingFunction error if an unknown import is detected

Configuration:

  • Added FailureBehavior configuration struct with three panic options:
    • panic_on_module_parsing_failure - terminates if module file parsing fails
    • panic_on_module_compilation_failure - terminates if WASM compilation fails
    • panic_on_invalid_signature - terminates if signature verification fails

Rationale

Previously, modules with invalid imports would fail at runtime when attempting to call undefined functions, making debugging difficult. By validating imports at compile time, errors are surfaced earlier with clearer messages.

The refactored API registration code reduces maintenance burden and makes it easier to audit which functions are exposed to WASM modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant