feat(wasm): add sandbox host functions and extended ABI for term-challenge - #39
Conversation
Extend the validator node WASM executor and challenge registry to support term-challenge extended ABI with sandbox capabilities, new WASM exports (get_tasks, configure), and improved memory allocation handling. WASM Executor (wasm_executor.rs): - Fix alloc/allocate handling: try alloc(size) first (1 param), then fall back to allocate(size, align) (2 params), then raw memory offset. Extracted into reusable allocate_input() helper. - Add execute_get_tasks() to call get_tasks() export and read results. - Add execute_configure() to write config data and call configure(ptr, len). - Add execute_evaluation_with_sandbox() accepting SandboxPolicy alongside NetworkPolicy. Original execute_evaluation() delegates to it. - Register SandboxHostFunctions during WASM instantiation. Challenge Registry (registry.rs, discovery.rs): - Add sandbox_policy field to WasmModuleMetadata with builder method. - Add sandbox_policy field to DiscoveredChallenge. - Load companion .policy.json files when discovering WASM modules. - Scan challenges/ subdirectory alongside the main wasm_modules/ dir. - Extract scan_wasm_dir() helper to reduce duplication. WASM Runtime Interface (lib.rs, runtime.rs, sandbox.rs): - Add SandboxPolicy type with default, development, and term_challenge presets controlling allowed commands and execution time limits. - Add sandbox.rs module with SandboxHostFunctions implementing the platform_sandbox namespace (sandbox_exec, sandbox_get_tasks, sandbox_configure, sandbox_status host functions). - Add SandboxHostState, SandboxHostConfig, SandboxHostError types. - Add sandbox_policy to InstanceConfig and RuntimeState. - Add call_i32_return_i32() to ChallengeInstance for single-arg exports. Validator Node (main.rs): - Create challenges/ subdirectory under wasm_module_dir on startup.
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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)
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. Comment |
…-support # Conflicts: # bins/validator-node/src/wasm_executor.rs # crates/wasm-runtime-interface/src/runtime.rs
…-support # Conflicts: # crates/wasm-runtime-interface/src/lib.rs # crates/wasm-runtime-interface/src/runtime.rs
Summary
Add sandbox execution support to the WASM runtime and extend the challenge executor with new ABI entry points (
get_tasks,configure) required by term-challenge modules.Changes
WASM Executor (
bins/validator-node)allocate_input()helper that triesalloc(size)first, then falls back toallocate(size, align), and finally to a memory-offset fallbackexecute_evaluation_with_sandbox()method accepting aSandboxPolicyexecute_get_tasks()to call the WASMget_tasksexport and read result from linear memoryexecute_configure()to write configuration data into WASM memory and invoke theconfigure(ptr, len)exportSandboxHostFunctionsalongside existingNetworkHostFunctionsduring instantiationchallenges/subdirectory under the WASM module dir on startupWASM Runtime Interface (
crates/wasm-runtime-interface)SandboxPolicytype withdefault(),development(), andterm_challenge()presets controlling allowed commands and execution time limitssandboxmodule with host function registrar (platform_sandboxnamespace), status codes, error types, and sandbox state managementsandbox_policyfield toInstanceConfigandRuntimeStatecall_i32_return_i32()helper toChallengeInstancefor single-arg WASM exportsChallenge Registry (
crates/challenge-registry)sandbox_policy: Option<SandboxPolicy>toWasmModuleMetadatawithwith_sandbox_policy()buildersandbox_policyfield toDiscoveredChallengechallenges/subdirectory when discovering WASM modules.policy.jsonfiles for sandbox/network policy configurationscan_wasm_dir()andload_sandbox_policy()helpers to reduce duplication