Skip to content

fix(crypto): harden cryptographic validation and security in ECKey, SM2, and shielded APIs#6

Closed
Federico2014 wants to merge 5 commits intodevelopfrom
feature/optimize_crypto
Closed

fix(crypto): harden cryptographic validation and security in ECKey, SM2, and shielded APIs#6
Federico2014 wants to merge 5 commits intodevelopfrom
feature/optimize_crypto

Conversation

@Federico2014
Copy link
Copy Markdown
Owner

@Federico2014 Federico2014 commented Apr 7, 2026

What does this PR do?

This PR hardens the security and robustness of cryptographic subsystems in java-tron across five areas:

  1. Remove unused topicsList from shielded TRC20 log APIs – eliminates dead parameter from ScanShieldedTRC20NotesByIvk/Ovk HTTP endpoints and RPC services.
  2. Shielded transaction API security enhancement – tightens input validation in Wallet, ZenTransactionBuilder, ShieldedTRC20ParametersBuilder, and related servlets.
  3. SM2 robustness and deterministic signatures – enforces deterministic RFC 6979 nonce generation, validates curve points on deserialization, and rejects weak or low-order keys.
  4. ECKey input validation – adds strict validation on public key coordinates, rejects infinity/low-order points, enforces bounds on all deserialized key material.
  5. Signature and private key validation – hardens ECKey, Rsv, and SignUtils to reject out-of-range scalars, invalid recovery IDs, and malformed signature encodings.

Why are these changes required?

These fixes address signature malleability and input validation vulnerabilities where crafted inputs could bypass cryptographic checks, produce incorrect signatures, or expose internal data through API responses.

This PR has been tested by:

  • Unit Tests (ECKeyTest, SM2KeyTest, ShieldedTRC20BuilderTest, WalletMockTest, ShieldedTransferActuatorTest, RpcApiServicesTest, ArgsTest)
  • Manual Testing

Follow up

Consider fuzzing the signature verification path with property-based tests.

Extra details

  • Removes sprout-verifying.key binary artifact from the repository root.
  • Proto: api.proto updated to remove deprecated topicsList fields from shielded scan responses.

Summary by cubic

Strengthens crypto validation and shielded APIs: strict key/signature checks, deterministic SM2 signatures, and safer shielded TRC20 scan endpoints. Shielded transaction APIs are now opt-in by default.

  • Bug Fixes

    • ECKey/SM2: validate curve points, reject infinity/low-order points, and out‑of‑range scalars; tighten recovery ID and signature encoding checks.
    • SM2Signer: use deterministic nonces (HMacDSAKCalculator with SM3) to prevent malleability.
    • SignUtils: add isValidPrivateKey(...) and enforce keystore private key validation in WitnessInitializer.
    • Shielded TRC20 scan APIs: remove deprecated events/topicsList; RPC/HTTP now reject requests that include them; api.proto marks these fields as deprecated.
    • Shielded builders: use overflow‑safe math for valueBalance to avoid silent wraparound.
  • Migration

    • Stop sending events/topicsList to shielded TRC20 scan endpoints; requests including them will fail. Update clients generated from api.proto if needed.
    • Shielded transaction APIs are disabled by default. To opt in, set node.allowShieldedTransactionApi = true (legacy node.fullNodeAllowShieldedTransaction is supported but deprecated).
    • Keystore loading now fails fast on invalid private keys; ensure keys are valid before deployment.

Written for commit 4f3c68b. Summary will update on new commits.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 7, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a3973833-45fd-424e-bec8-d00ec8c6efe3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/optimize_crypto

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant