feat(crypto): add post-quantum signature support for nile#41
feat(crypto): add post-quantum signature support for nile#41Federico2014 wants to merge 17 commits into
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.
5 issues found across 81 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
e28e6b4 to
f77f97c
Compare
59f5a22 to
2e0a76b
Compare
- Consolidate PQ scheme validation into isPqSchemeAllowed (warns on unregistered scheme, returns false); drop the redundant PQSchemeRegistry.contains() pre-checks in BlockCapsule/TransactionCapsule/Manager/RelayService and unify wording to "not allowed". - Rename RelayService keySize -> ecdsaKeySize for clarity. - Reject a single account authorising both an ECDSA and a PQ witness key (LocalWitnesses.checkWitnessAddressConflict, invoked from Args after merging witnesses), with unit tests.
2e0a76b to
42c4b53
Compare
…com/Federico2014/java-tron into feature/pqc-signature-v4.8.2-build1
2e216bb to
d1cf710
Compare
…y service field names
974ab77 to
a02783b
Compare
c27c474 to
a9e4172
Compare
There was a problem hiding this comment.
1 issue found across 7 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
1f3514d to
2e27377
Compare
2e27377 to
92d2fa4
Compare
There was a problem hiding this comment.
2 issues found across 1 file (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
0e9bbe3 to
3e3056b
Compare
…re block generation
There was a problem hiding this comment.
1 issue found across 5 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
30203d8 to
c29f847
Compare
c29f847 to
bc5736b
Compare
There was a problem hiding this comment.
1 issue found across 3 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
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 may contain any combination of the following material fields —privateKeytakes priority at load time;seedis retained as a backup field when both are present: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).privateKey—FN_DSA_512must also supplypublicKey(BouncyCastle exposes no API to derive it from the private key);ML_DSA_44suppliesprivateKeyonly —publicKeyis derived automatically, but may optionally be included for verification (if present it must match the derived value, otherwise the node rejects the file).address— informational field written bypq-key new, ignored at load time.PqKeyFile(Jackson-bound) is the JSON shape.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
Five new precompiles covering single verify, batch verify, and mixed multi-sign for both PQ schemes:
0x16VerifyFnDsa5120x17BatchValidateFnDsa5120x18VerifyMlDsa440x19BatchValidateMlDsa440x1aValidateMultiPQSigEnergy values are calibrated via JMH benchmarks (warmup 5×2s, measurement 10×3s, 2 forks, 20 samples) using
ECRecover.execute()— precompile 0x01, 3000 energy, 816.9 µs — as the reference unit. All benchmarks callcontract.execute(input)to cover the full precompile path (ABI decode, slot scan, address derivation, verify):0x16verify()0x17per entrycomputeAddress()+verify()0x18verify()0x19per entrycomputeAddress()+verify()0x1aFN-DSA entry0x1aML-DSA entryECRecover baseline: 816.9 µs → 3000 energy (CV 1.9%); all PQ values rounded up to the nearest 10.
0x1a ValidateMultiPQSig.execute()requires chain DB and cannot be benchmarked in isolation — its per-entry crypto work is identical to 0x17/0x19 respectively, so those values are reused.These values are proposed based on this benchmark run and subject to community review before mainnet activation.
Relay / fast-forward support
RelayServicesigns and verifiesHelloMessageusing either legacy signatures orPQAuthSig.Toolkit (
plugins)Toolkit.jar pq-key newcommand generates a post-quantum key JSON file.FN_DSA_512; default output directory:Wallet/.{ "scheme": "FN_DSA_512", "seed": "<96 hex chars>", "privateKey": "<2560 hex chars>", "publicKey": "<1792 hex chars>", "address": "T..." }ML_DSA_44files follow the same structure with scheme-appropriate lengths (seed 64 hex, privateKey 5120 hex, publicKey 2624 hex).0600permissions (owner read/write only).--jsonflag prints a machine-readable summary (address,scheme,file).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.PQWitnessNode.writeWitnessConfigemits the full key file format (seed,privateKey,publicKey,address), matching thepq-key newoutput../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.