Repository navigation
Conversation
|
[NIT / Hardening] Validate the diversifier in Both existing builders already reject invalid diversifiers before invoking the output-proof wrapper:
The encryption path rejects invalid diversifiers through Note.encrypt() and NoteEncryption.fromDiversifier(), which returns an empty result when However, JLibrustzcash.librustzcashSaplingOutputProof() forwards parameters directly to native code without independently validating the diversifier. Calling Consider adding parameter validation and an explicit diversifier check at the wrapper boundary, along with a regression test confirming that an invalid diversifier is rejected before the native output-proof call. This is a defense-in-depth improvement for future direct callers; the two existing builder paths are already protected. |
| params.valid(); | ||
| INSTANCE.librustzcashZip32XskDerive(params.getData(), params.getSize(), params.getM_bytes()); | ||
| } | ||
|
|
||
| public static boolean librustzcashZip32XfvkAddress(Zip32XfvkAddressParams params) { | ||
| public static boolean librustzcashZip32XfvkAddress(Zip32XfvkAddressParams params) | ||
| throws ZksnarkException { | ||
| params.valid(); |
There was a problem hiding this comment.
[NIT / SDK & Native Hardening] Handle invalid serialized ZIP32 keys without native panics.
The new params.valid() checks validate buffer lengths but do not validate the serialized extended-key contents:
- librustzcashZip32XskDerive():
Zip32XskDeriveParams.valid()checks the 169-byte buffer lengths, but native decoding ofxsk_parentstill uses ExtendedSpendingKey::read(...).expect(...). - librustzcashZip32XfvkAddress():
Zip32XfvkAddressParams.valid()checks buffer lengths, but native decoding ofxfvkstill uses ExtendedFullViewingKey::read(...).expect(...).
Consequently, correctly sized buffers containing invalid serialized keys can still trigger a native panic during decoding.
I found no production callers of these wrappers in the current java-tron tree, so this can be tracked as a follow-up rather than blocking this PR.
Before accepting untrusted extended keys through these interfaces, please replace the native expect() calls with controlled error handling and propagate failures safely through JNI and the SDK. The derive API currently returns void, so its failure-reporting mechanism also needs to be addressed.
Please add regression tests using correctly sized but invalid serialized XSK/XFVK values, verifying that decoding failures are handled without native panics.
The absence of production callers in java-tron does not establish whether other SDK consumers expose these functions to untrusted inputs.
There was a problem hiding this comment.
@3for Agreed. The length checks do not validate serialized key contents, so this remains incomplete, as noted in the PR description.
I'll address it in a separate SDK/native follow-up: replace both decoding expect() calls with controlled error handling, propagate failures through JNI and Java—including an explicit failure contract for XSK derivation—and add regression tests using correctly sized but invalid XSK/XFVK inputs. Other SDK consumers also need to be considered, even though these wrappers currently have no production callers in java-tron.
| result); | ||
| if (!JLibrustzcash.librustzcashComputeNf(computeNfParams)) { | ||
| return null; | ||
| throw new ZksnarkException("compute nullifier error"); |
There was a problem hiding this comment.
[SHOULD] Native nullifier failures still cannot reach this check.
JLibrustzcash.librustzcashComputeNf() calls the SDK and unconditionally returns true. The SDK Java method returns void, and the JNI bridge discards Rust’s boolean return value.
Rust can return false before writing the output buffer. The Java-side ComputeNfParams.valid() checks lengths and non-negative values, but does not cover all native semantic checks. Consequently, createShieldNullifier() can still return the untouched output buffer as a successful result.
The new null check in isSpend() has the same limitation: Note.nullifier() returns null only when that wrapper returns false.
Please preserve an explicit success/failure status through Rust → JNI → SDK Java → JLibrustzcash, or provide an equivalent reliable error contract. Add regression coverage across that boundary: the current failure tests mock JLibrustzcash itself, so they exercise the Wallet branches without detecting the status loss. An all-zero output check should not substitute for the success status.
There was a problem hiding this comment.
@3for Agreed. The current checks do not complete the fix: JNI discards the native return value, the SDK method returns void, and librustzcashComputeNf() always returns true. The mocked tests only verify the Wallet failure branches.
As noted in the PR description, this remains incomplete until the SDK/JNI/native changes are published and the dependency is upgraded. I'll wire librustzcashSaplingComputeNfChecked through the Java wrapper and add regression coverage exercising a real native failure through JNI and the SDK, verifying that it cannot produce a successful nullifier result. An all-zero output check will not substitute for an explicit failure status.
|
[NIT / Hardening] Stop ZK-SNARK initialization when parameter file copying fails. In ZksnarkInitService.getParamsFile(), an As a result, initialization can proceed with a missing or incomplete parameter file. The native implementation uses Please stop initialization when copying fails, clean up any partially written file, and return the destination path only after a successful copy. As parameter initialization runs during normal node startup, including when shielded transaction APIs are disabled. Please also add a regression test verifying that a copy failure prevents the native initialization call. This can be addressed entirely within java-tron as a non-blocking follow-up. |
|
@3for I've implemented both hardening changes:
The targeted tests, Checkstyle, Math usage scan, and diff checks passed. |
| @@ -67,7 +68,14 @@ private static String getParamsFile(String fileName) { | |||
| } | |||
| FileUtils.copyToFile(in, fileOut); | |||
There was a problem hiding this comment.
[NIT] Could we allocate these parameter files atomically with Files.createTempFile, preferably in a node-private temporary directory, instead of constructing timestamp-based paths? Please preserve the new cleanup and error propagation behavior. The native hash check validates parameter contents, but does not establish ownership of the destination used by the earlier copy operation.
There was a problem hiding this comment.
Thanks for the suggestion. We will keep this hotfix scoped and address it in a follow-up — switching to Files.createTempFile (or a node-private temp directory) while preserving the cleanup and error propagation added here.
430207d to
d25a731
Compare
|
[NIT] Decoding the burn record at |
waynercheung
left a comment
There was a problem hiding this comment.
LGTM at d25a731b5a. Verified on aarch64 / JDK 17 with the real native library:
- Both identity
akencodings and invalid output diversifiers are rejected before native proof generation. Consensus verification is unchanged. - The new ABI parameter validation rejects malformed field lengths before encoding, while valid calldata remains unchanged. Signature-source selection and the existing Wallet burn validations are preserved.
- Related shielded tests and Checkstyle pass; 29/30 mutants killed (see inline for the surviving mutant).
[SHOULD] Please update the PR description to include the output-proof and ABI validation and current verification results, and link tracking issues for the deferred SDK/JNI and temporary-file hardening work.
33825d9 to
74cdf6b
Compare
What does this PR do?
Harden shielded proof generation, parameter encoding, note scanning, and initialization:
ContractValidateExceptionwith a fixed client-facing message instead of a generic HTTP internal-server-error message. Preserve0xprefixes, odd-length zero padding, and existing burn-record length rejection behavior.ZCASH_INITwhen parameter-file copying fails, attempt to remove the partial file, and avoid calling native initialization with an incomplete file.Why are these changes required?
Identity spend keys can terminate the node during native proof generation. Ignored signature failures can publish invalid output, malformed ABI fields can shift encoded arguments, and sender-controlled malformed note plaintexts can interrupt an entire scan range. Parameter-copy failures previously allowed initialization to continue with a missing or incomplete file.
The changes reject these failures at the relevant Java boundaries while preserving valid transaction construction and scan results. Nullifier failure propagation still requires the SDK/native follow-up below.
This PR has been tested by:
./gradlew clean build -x testpassed on macOS with the x86_64 / JDK 8 runtime.WalletShieldedDescriptionValidationTest,UtilProcessErrorTest, and the fiveNoteEncDecryTest.testGetTriggerInputBurn*cases.ShieldedNativeValidationTestpassed. The new case sets byte 30 of an otherwise identity-like encoding for both sign bits; changing the loop bound fromi < 31toi < 30was verified to fail this test. The correct bound was restored.74cdf6b32b, PR Check, Math usage, and single-node smoke tests passed. The PR Build matrix was still running when this description was updated.Follow up
librustzcashSaplingComputeNfChecked. The current Java wrapper still returns true; the mocked Wallet tests verify error branches, not end-to-end native failure propagation.Files.createTempFile, preferably in a node-private temporary directory, while preserving cleanup and error propagation.Extra details
The changes are confined to shielded API construction, scanning, and initialization across chainbase/framework. Dependencies, consensus verification rules, and public
Note.decodebehavior are unchanged. ZIP32 validation preserves empty/prefix seeds and unsigned hardened child indices; valid TRC20 ABI encoding is preserved.