feat(crypto): add post-quantum signature support#37
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
7 issues found across 74 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
2e71d25 to
1e01bdf
Compare
b91767c to
d44213a
Compare
…qc-signature-v4.8.2 # Conflicts: # framework/src/test/java/org/tron/core/services/http/UtilTest.java
a6226b7 to
4c6f644
Compare
4c6f644 to
72d52b1
Compare
fix(style): fix code style
There was a problem hiding this comment.
2 issues found across 10 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
|
You're iterating quickly on this pull request. To help protect your rate limits, cubic has paused automatic reviews on new pushes for now—when you're ready for another review, comment |
d5d05ca to
492503e
Compare
…xist at the same time
fix(config): refactor the config
|
You're iterating quickly on this pull request. To help protect your rate limits, cubic has paused automatic reviews on new pushes for now—when you're ready for another review, comment |
Summary
Adds post-quantum (PQ) signature support to TRON across protocol, crypto, transaction/block validation, TVM precompiles, witness configuration, consensus signing, relay handshakes, governance flags, and tests.
Two PQ schemes are supported, each independently gated by a committee proposal:
FN_DSA_512/ Falcon-512 (variable-length signature, max 667 B, pubkey 896 B)ML_DSA_44/ Dilithium-2 (fixed-length signature 2420 B, pubkey 1312 B)Protocol changes
PQSchemeenum:UNKNOWN_PQ_SCHEME,FN_DSA_512,ML_DSA_44.PQAuthSig { scheme, public_key, signature }as the shared PQ authentication envelope.repeated pq_auth_sigtoTransactionso ECDSA and PQ signatures coexist for account permission threshold checks.pq_auth_sigtoBlockHeader; legacywitness_signatureand PQpq_auth_sigare mutually exclusive.pq_auth_sigtoHelloMessagefor relay/fast-forward authentication by PQ witnesses.Address derivation
0x41 || deriveHash(scheme, public_key)[12..32], matching the ECDSA shape.PQSchemeRegistry.computeAddress(scheme, publicKey)is the single entry point.Crypto module (
crypto)FNDSA512: Falcon-512 sign/verify; variable-length signatures validated against the canonical[SIGNATURE_MIN_LENGTH, SIGNATURE_MAX_LENGTH]range.MLDSA44: ML-DSA-44 sign/verify; fixed-length 2420-byte signatures.PQSignature,PQSchemeRegistry,PqKeypair: shared PQ abstraction layer.PQSchemeRegistrycentralises key lengths, signature lengths, seed handling, address derivation, sign, verify, and block-size wire-size computation (computePQAuthSigWireSize).Governance and activation
ALLOW_FN_DSA_512(proposal id 99) andALLOW_ML_DSA_44(proposal id 100).VERSION_4_8_2.Witness configuration
localPqWitness.keys— a list of paths to JSON key files (relative paths resolve against the working directory); each file holds one keypair, keeping the long key material out ofconfig.conf.schemeand defines exactly one material source:seed—FN_DSA_512: 96 hex chars / 48 B (accepted with a drift warning — Falcon keygen is FFT-based and not bit-stable across JVMs or CPU architectures);ML_DSA_44: 64 hex chars / 32 B (deterministic, accepted without restriction).privateKey—FN_DSA_512must also supplypublicKey(BouncyCastle exposes no API to derive it from the private key);ML_DSA_44suppliesprivateKeyonly (public key is derived, sopublicKeymust be omitted).PqKeyFile(Jackson-bound) is the JSON shape;pq-witness-key.template.jsonships as a fill-in template.localPqWitness.accountAddressis set.Consensus and block production
generateBlockpre-reserves the exact proto3 wire size ofpq_auth_sig(viaPQSchemeRegistry.computePQAuthSigWireSize) before the transaction packing loop, preventing PQ SR blocks from exceeding the receiver-sidemaxBlockSizecheck inBlockMsgHandler.Transaction validation
TransactionCapsulevalidates mixed ECDSA + PQ signatures against the same account permission threshold.Permission.keys[].address.Block validation
Bandwidth
pq_auth_sigbytes are subtracted from net bandwidth as signature overhead (same treatment as ECDSAsignaturebytes).Transaction and pending pool limits
PQ_TRANS_IN_BLOCK_COUNTS).node.pqTransInPendingMaxCounts(default 1000).TVM precompiles
0x16 verifyFnDsa512: single Falcon-512 signature verification.0x17 batchValidateFnDsa512: batch Falcon-512 verification with bitmap result.0x18 verifyMlDsa44: ML-DSA-44 single verification (standard 1312-byte public key).0x19 batchValidateMlDsa44: batch ML-DSA-44 verification with bitmap result.0x1a validateMultiPQSig: unified ECDSA + PQ account-permission threshold verification.Relay / fast-forward support
RelayServicesigns and verifiesHelloMessageusing either legacy signatures orPQAuthSig.Example module (
example:pqc-example)example:pqc-example(packageorg.tron.example.pqc).PQWitnessNode: in-process PQ witness node with deterministic keypairs.PQFullNode: fullnode that dialsPQWitnessNodevia P2P and validates PQ-signed blocks.PQClient: broadcasts a single PQ-signed transfer transaction.PQTxSender: continuous multi-scheme (FN-DSA-512, ML-DSA-44, ECDSA) transfer and TRC20 load generator../gradlew :example:pqc-example:run -PmainClass=org.tron.example.pqc.PQWitnessNode.Compatibility
UNKNOWN_PQ_SCHEMEis reserved and never treated as a valid signing scheme.Tests
PQSchemeRegistry,PQSignature.