fix(crypto): reject public Sapling encryption shared secrets

FE
2d ago
+144-0

What does this PR do?

Reject the canonical identity shared point in NoteEncryption.encryptToRecipient before key derivation or ciphertext creation. Both native shielded transactions and shielded TRC20 builders propagate this failure before output proving. The check covers identity aliases, small-order recipient points and a zero ephemeral secret.

Why are these changes required?

A degenerate recipient key can make the shared point public, exposing the amount and memo after the output is published. Check the canonical result of native key agreement rather than matching a particular recipient encoding. This sender-only change works with the existing SDK 1.0.0 and leaves historical note decryption and consensus verification unchanged.

This PR has been tested by:

  • Five new real-JNI tests cover identity aliases/order-four points, rejection followed by successful encryption and decryption, zero ephemeral secrets, rejection in both transaction builders before proving, and reading historical degenerate ciphertext.
  • These tests plus the two existing SaplingNoteTest cases passed with the bundled SDK and again with rebuilt normal release JNI (7 tests per run).
  • The identity-recipient regression fails against the original NoteEncryption implementation.
  • Changed production classes and their direct callers compiled with JDK 8 against locally built node dependencies. Focused Checkstyle 8.7 using the repository configuration passed; the forbidden Math check passed.
  • The Gradle offline test/Checkstyle invocation was blocked by missing cached dependencies in the p2p dependency graph. The focused runs used javac/JUnit with the existing local FullNode dependency JAR; they do not substitute for the full Gradle build/test matrix. Full CI remains required.

Follow up

Companion Rust/SDK changes reject these inputs during output proof generation and add native regressions. The node guard can ship independently without a dependency update.

Extra details

Based on Federico2014/java-tron release_v4.8.3 at 9f53b510. Cherry-picks the recipient fix from tronprotocol/java-tron#7133 without unrelated upstream commits. No protocol, transaction-validation, SDK dependency, or historical-reading changes.

Companion PRs: https://github.com/tronprotocol/librustzcash/pull/18 and https://github.com/tronprotocol/zksnark-java-sdk/pull/25.


Summary by cubic

Rejects degenerate Sapling recipient keys so the shared encryption secret can never become public.

A recipient key that forces key agreement to the identity point makes the shared secret public, exposing the note amount and memo once the output is published. NoteEncryption.encryptToRecipient now returns empty for the canonical identity shared point before key derivation or ciphertext creation, and both native shielded transactions and shielded TRC20 builders fail before output proving.

  • Sender-only change; historical note decryption and consensus verification are unchanged.
  • Works with the existing SDK 1.0.0 and needs no dependency update.
  • New real-JNI tests cover identity aliases, small-order points, zero ephemeral secrets, rejection in both builders, and reading historical degenerate ciphertext.