Skip to content

feat(wasm-runtime): align host ABI, register storage functions, add log/timestamp - #32

Merged
echobt merged 4 commits into
mainfrom
feat/wasm-host-abi-alignment-and-storage
Feb 17, 2026
Merged

feat(wasm-runtime): align host ABI, register storage functions, add log/timestamp#32
echobt merged 4 commits into
mainfrom
feat/wasm-host-abi-alignment-and-storage

Conversation

@echobt

@echobt echobt commented Feb 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Aligns the WASM host-side ABI with the guest SDK signatures, registers missing platform_storage host functions, and adds log_message/get_timestamp utility host functions.

Changes

ABI Fixes (network.rs)

  • Fix http_get signature: remove resp_len param, use default buffer size (64KB) to match guest SDK 4-param ABI
  • Fix dns_resolve signature: remove resp_len param, use default buffer size (4KB)
  • Adjust http_post to accept extra unused param for forward compatibility

New Host Functions (network.rs)

  • log_message(level, msg_ptr, msg_len): reads string from WASM memory and routes to tracing::info!/warn!/error! based on level
  • get_timestamp() -> i64: returns UTC millis, with optional fixed timestamp from RuntimeState for deterministic consensus execution

Storage Host Functions (storage.rs)

  • Implement StorageHostFunctions struct implementing HostFunctionRegistrar
  • Register storage_get(key_ptr, key_len, value_ptr) -> i32 under platform_storage module
  • Register storage_set(key_ptr, key_len, value_ptr, value_len) -> i32 with consensus-gated write support
  • Add WASM memory read/write helpers and get_memory utility
  • Add StorageOperation::Set variant and export HOST_STORAGE_SET constant
  • Wire StorageHostState to use StorageBackend via Arc

Runtime Integration (runtime.rs)

  • Extend InstanceConfig with storage_host_config, storage_backend, and fixed_timestamp_ms
  • Extend RuntimeState with storage_state and fixed_timestamp_ms
  • Register both NetworkHostFunctions and StorageHostFunctions in the linker during instance creation
  • Add reset_storage_state() and storage metric accessors to ChallengeInstance

Exports (lib.rs)

  • Export StorageHostFunctions, HOST_STORAGE_SET, HOST_LOG_MESSAGE, HOST_GET_TIMESTAMP

Validator Node (wasm_executor.rs)

  • Use ..Default::default() for new InstanceConfig fields

…ons, add log/timestamp support

Fix critical ABI mismatches in network host functions and implement
missing storage host function registrations to align the host-side
runtime with the guest SDK expectations.

Network ABI fixes (network.rs):
- Remove extra resp_len param from http_get and dns_resolve signatures
  to match the guest SDK 4-param ABI (req_ptr, req_len, resp_ptr) with
  default buffer sizes (64KB for HTTP, 4KB for DNS).
- Add extra _extra param to http_post to align with guest expectations.
- Add log_message host function: reads message string from WASM memory
  and dispatches to tracing::info/warn/error based on level parameter.
- Add get_timestamp host function: returns UTC millis, with support for
  a fixed_timestamp_ms in RuntimeState for deterministic consensus.

Storage host functions (storage.rs):
- Implement StorageHostFunctions struct with HostFunctionRegistrar trait,
  registering storage_get and storage_set under platform_storage module.
- storage_get reads key from WASM memory, fetches from backend, writes
  value back to WASM memory, tracks bytes_read and operations_count.
- storage_set reads key+value from WASM memory, validates against config
  constraints (key/value limits, consensus gating), writes via backend,
  tracks bytes_written and operations_count.
- Add helper functions for WASM memory read/write with bounds checking.
- Add StorageOperation::Set variant and HOST_STORAGE_SET constant.
- Update StorageHostState::new to accept a StorageBackend Arc parameter.

Runtime integration (runtime.rs):
- Extend InstanceConfig and RuntimeState with storage_state,
  storage_backend, storage_host_config, and fixed_timestamp_ms fields.
- Register both NetworkHostFunctions and StorageHostFunctions with the
  linker during instance creation.
- Add storage state reset and counter accessors to ChallengeInstance.

Module exports (lib.rs):
- Export StorageHostFunctions, HOST_STORAGE_SET, HOST_LOG_MESSAGE,
  and HOST_GET_TIMESTAMP from the crate root.

Downstream update (wasm_executor.rs):
- Use ..Default::default() in InstanceConfig construction to pick up
  new fields without breaking existing call sites.
@coderabbitai

coderabbitai Bot commented Feb 17, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@echobt has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 17 minutes and 21 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/wasm-host-abi-alignment-and-storage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@echobt
echobt merged commit c56d778 into main Feb 17, 2026
11 checks passed
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