fix: preserve Sapling proving state on failure and report ZIP32 decoding errors
A failed Sapling Spend or Output proof could leave commitment randomness in the proving context. A caller that reused the context after a failure could then fail to create a binding signature for an otherwise valid transaction. The Spend path could also write the randomized key (rk) before returning false.
Sapling proof generation
- Prepare proof outputs locally. Update the context and copy the outputs only after proof creation, Spend proof verification where applicable, and serialization succeed. If either entry point returns
false, the context and all output buffers retain their previous values. - Reject small-order Spend authorization keys (
ak). Returnfalsefor an incorrect witness depth prefix or sibling-node length prefix, replacing the two assertions on those fields. - Return
falsewhen required proving parameters or the Spend verification key are unavailable, whenOsRng::new()fails, or when proof creation returns an error.
ZIP32 native interfaces
- Add
librustzcash_zip32_xsk_derive_checked, which returnsfalseif the parent spending key cannot be decoded or its depth is already 255. Keep the existingvoidentry point as a wrapper. Callers that need the failure status must use the checked entry point. - Return
falseon viewing-key decoding errors inlibrustzcash_zip32_xfvk_deriveandlibrustzcash_zip32_xfvk_address. Viewing-key child derivation also rejects a parent at depth 255.
Validation
- All 10 Rust library tests passed on macOS x86_64 with
cargo test --offline --locked --package librustzcash --lib. The release-mode run ata57f7b2also passed all 10 tests. - In the companion SDK, rebuilding the macOS x86_64 JNI library against
a57f7b2and runningmvn -o clean packagepassed all 41 tests, including proof failure followed by another proof on the same context and the complete transaction flow. Three SDK regression tests failed against the pre-fix library and passed after rebuilding.
Downstream adoption
The four-platform builds in SDK #17 and SDK #19 use Rust revision 45f8049. To ship these fixes, the SDK needs to pin the merged Rust revision and rebuild its four bundled libraries. To propagate XSK derivation failures to Java, the JNI wrapper also needs to call the checked entry point and handle false before copying the output. After the SDK release, java-tron can verify proof-failure recovery using the native libraries in its packaged JAR.