Repository navigation
Description
Summary
platform-wallet-ffi's shared blocking primitive, block_on_worker, propagates a panic from the tokio worker back onto the FFI thread with .expect(...). If the panic occurs inside an async wallet operation, it unwinds out of the extern "C" FFI function. Unwinding across an extern "C" boundary aborts the process (a guaranteed abort since Rust 1.81, previously UB) — i.e. any deep panic in the build / prove / broadcast / sync pipeline hard-crashes the host app (iOS, etc.) instead of returning a recoverable error.
There is no memory corruption, no fund loss, and no consensus impact — this is a host-app robustness / crash-resilience issue.
Location
packages/rs-platform-wallet-ffi/src/runtime.rs:49-56
pub(crate) fn block_on_worker<F>(future: F) -> F::Output
where
F: std::future::Future + Send + 'static,
F::Output: Send + 'static,
{
let rt = runtime();
rt.block_on(async move { rt.spawn(future).await.expect("tokio worker panicked") })
}rt.spawn(future).await returns Err(JoinError) if the worker future panics; the .expect("tokio worker panicked") then re-panics on the thread driving block_on — which is the caller's FFI thread inside an extern "C" function.
Scope / impact
block_on_worker is the shared blocking entry point for every async FFI operation in platform-wallet-ffi — 46 call sites across 28 files (shielded send/fund/resume, wallet sync, broadcast, etc.). Any unhandled panic anywhere in those async paths (e.g. an unwrap/expect/arithmetic panic deep in proving, GroveDB, or networking) propagates as a process abort on the host rather than a PlatformWalletFFIResult error the host can handle and surface to the user.
Severity
Low — robustness only. No UB (the abort is defined behavior on current toolchains), no fund/consensus risk. But a host-app crash on any deep panic is a poor failure mode for a mobile SDK, where a recoverable error is strongly preferable.
Provenance
Pre-existing; not introduced by any single change. Surfaced during the adversarial audit of the shield-fees PR (finding L6), which explicitly confirmed the PR does not aggravate it — the new parse_optional_surplus_output helper returns Result and never panics into the worker. Filed separately so it can be fixed as shared FFI hardening rather than bundled into a consensus-fee change.
Recommended fix
Catch the panic at the FFI boundary and convert it to a recoverable error instead of letting it unwind:
- Wrap the worker future in
std::panic::catch_unwind(e.g.AssertUnwindSafe(future).catch_unwind().awaitfromfutures::FutureExt, or catch theJoinError::is_panic()inblock_on_workerand map it), and on a caught panic returnPlatformWalletFFIResult::err(ErrorInternal, <message>)from each wrapper. - Verify the crate (and any consuming build profile) is not compiled with
panic = "abort", sincecatch_unwindcannot catch under abort. (Nopanic = "abort"is set inpackages/rs-platform-wallet-ffi/Cargo.tomlor the workspace root today — keep it that way for the FFI crate.) - Consider centralizing this so all 46 call sites benefit without per-wrapper changes (e.g. have
block_on_workeritself return aResult/sentinel on worker panic, or add ablock_on_worker_catchingvariant used by the FFI wrappers).
Acceptance criteria
- A panic inside an async wallet FFI operation returns a
PlatformWalletFFIResulterror (e.g.ErrorInternal) to the caller instead of aborting the process. - The FFI crate is confirmed to use
panic = "unwind"(notabort). - A regression test induces a worker-future panic and asserts the FFI returns an error rather than crashing the test process.
Activity
Aakilahamed006 commentedon Jun 16, 2026
Hi, I'd like to work on this issue if it's still available.
My understanding is that the fix would involve preventing worker panics from unwinding across the FFI boundary, converting them into a recoverable PlatformWalletFFIResult error, and adding regression tests to verify the process does not abort.
Please let me know if there are any preferred implementation details before I start working on a PR.