fix(vm): treat unallocated tables as empty instead of panicking - #175
fix(vm): treat unallocated tables as empty instead of panicking#175dmitry123 wants to merge 1 commit into
Conversation
|
Warning Review limit reached
Next review available in: 57 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
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 |
Criterion results (vs baseline)Heads-up: runner perf is noisy; treat deltas as a smoke check. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Fixes FLU-1097.
Problem
A verified rwasm module can reference a table index it never grows, and every table op then panicked the interpreter instead of trapping:
Tables enter
RwasmStore::tablesonly when the module executesTableGrow— the only op that used.entry(idx).or_default(). Verification accepts any index< N_MAX_TABLESand cannot do better, since table indices carry no declaration. Nine call sites acrosstable.rsandcontrol_flow.rsdid.expect("rwasm: unresolved table segment")/.expect("rwasm: missing table"), so in a node a bad contract became a process crash — mid-execution, leaving the store with a dirty value stack, call stack, andlast_signature.Fix
All table lookups go through a single
resolve_tablehelper that materializes a missing table as an empty one, so an ungrown table behaves as a zero-length table. This matches Wasm semantics more closely than trapping outright:table.sizereturns 0,table.fill/table.copywithn == 0succeed, and every element access is bound-checked intoTrapCode::TableOutOfBoundsbyTableEntity. Behaviour for translator-produced modules is unchanged —emit_table_segmentemits aTableGrowper declared table, so the tables always exist.Unresolved syscall index (4a)
Left as-is per the discussion on the ticket: an index the import linker can't resolve is a fatal error, not a trap. The params/results counts come from the linker, so an unresolved index leaves no way to know how many values to pop, and any guess would desynchronize the value stack — zkVM proving needs the same trace on every run. Restricting the reachable syscall set is the linker's job, and
always_failing_syscall_handleris how a declared-but-forbidden syscall is rejected.invoke_syscallnow carries a doc comment explaining this.Tests
New
tests/tables.rs— 12 cases, each building a module that passesnew_verifiedand then executing it:table.sizeof an ungrown table returns 0table.get/table.set/table.fill/table.copy(across tables and within one) trap withTableOutOfBoundstable.fill/table.copyon ungrown tables succeed, per Wasm semanticstable.initinto an ungrown table trapscall_indirect/return_call_indirectthrough an ungrown table trapcargo testandcargo clippy --all-targets --all-featuresare clean. The two--all-featuresfailures intests/wasmtime.rs(test_wasmtime_disabled_f32_sqrt,test_wasmtime_disabled_f64_div) are pre-existing ondeveland unrelated — they were verified to fail on a clean checkout too.