fix: propagate contained Rust panics through JNI
Propagate contained Rust panics as Java exceptions instead of allowing them to terminate the JVM or appear to succeed. This is the JNI companion to https://github.com/tronprotocol/librustzcash/pull/16.
- All 31
LibrustzcashJNImethods inspect Rust's read-and-clear thread-local status. The scope guard throwsIllegalStateExceptionafter normal resource cleanup and preserves any pending Java exception. - Eleven native void operations use checked replacements, and their
falseresults are propagated even without a panic status. Checked initialization reports its new panic code 8. - Keep Java method signatures and ordinary boolean validation failures unchanged. Rust stages outputs and context updates before publication.
- Pin
rust/librustzcashtob7a153df69bf0ce986f9d728c19bfd9d4744c81dusing a gitlink, not copied submodule files. - Add an opt-in
ZKSNARK_PANIC_TESTSCMake configuration and three child-JVM scenarios. Instrumented Rust uses a separate target directory and the test JNI cannot be installed by CMake.
This PR targets develop and includes PR #21's checked-initialization commit as a prerequisite, followed by this panic-propagation commit. PR #21 and the independent randomness/Merkle PRs are unchanged. The prerequisite is needed to avoid recovery around partially published global parameters; release integration must combine all intended independent fixes into the final Rust pin.
Validation on macOS x86_64 / JDK 8:
- Instrumented release JNI: 38 Java tests passed. Tests cover all JNI methods, CPU-pool/scoped-worker panics, thread isolation, a panicking payload destructor, output preservation, real Spend/Output proof generation and verification, same-context retries, final binding signatures, and poisoned initialization.
- All 3 panic scenarios also pass using java-tron's production parameters and trusted hashes.
- Normal release JNI with no injection symbols: 35 tests passed. Rust library unit tests: 20 passed, 1 fixture-dependent test ignored by default (initialization covered by the JNI tests).
- Both CMake configurations generate successfully; build/install rules verify artifact isolation and no test-library installation. Local JNI compilation linked release Rust with the existing libsodium archive.
- Rust compilation explicitly rejects a forced
panic=abortbuild.
Draft for release integration: the four packaged macOS/Linux x86_64/aarch64 JNI binaries have not been regenerated. Before release, rebuild without injection, run tests against each final artifact, publish the SDK, and update java-tron's dependency. Old Rust void exports deliberately remain fatal on failure; merely relinking an old JNI does not activate this recovery contract. This handles unwinding Rust panics, not native memory corruption or OOM/explicit aborts.
Reproduction and build flags: docs/ffi-panic-boundary.md. No Sprout implementation changes.