Skip to content

feat: Add ml-dsa 65 key type - #5875

Merged
Eric-Warehime merged 15 commits into
mainfrom
eric/pq
May 27, 2026
Merged

Eric-Warehime merged 15 commits into
mainfrom
eric/pq

Conversation

@Eric-Warehime

Copy link
Copy Markdown
Collaborator

Adds ML-DSA-65 key type as an option for validators looking for post-quantum secure signing algorithms.

  • Uses the circl library for all of the crypto.
  • Minimally integrates into the places it needs to in comet as an option for validator keys.
  • Adds e2e tests for networks fully based on the new key type

PR checklist

  • Tests written/updated
  • Changelog entry added in CHANGELOG.md
  • Updated relevant documentation (docs/ or spec/) and code comments

@Eric-Warehime
Eric-Warehime requested a review from a team as a code owner May 19, 2026 19:01
@greptile-apps

greptile-apps Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds ML-DSA-65 (NIST FIPS 204, a post-quantum lattice-based signature scheme) as a new validator key type in CometBFT, using the cloudflare/circl library. The implementation spans a new crypto/mldsa65 package, protobuf schema extension, JSON codec registration, and e2e test infrastructure; it also adjusts block-size accounting constants to accommodate ML-DSA-65's significantly larger signatures (3309 bytes vs 96 bytes for BLS12-381).

  • New crypto/mldsa65 package — provides PrivKey/PubKey types backed by circl, a 4096-entry LRU cachingVerifier for public keys (mirroring the ed25519 pattern), and deterministic key derivation from a 32-byte seed.
  • Block-size and signature-size constants updated — MaxSignatureSize and MaxCommitSigBytes are now computed vars (not consts) to incorporate the new key type's sizes; test fixtures and the tx-filter test are adjusted accordingly.
  • E2e test coverage added — a new mldsa65.toml network manifest and a TestMlDsa65Network unit test exercise the full key-generation → encode → sign → verify round-trip without launching Docker containers; the e2e generator's random key-type pool now includes mldsa65.KeyType.

Confidence Score: 5/5

The core cryptographic wiring is correct — circl's Verify and SignTo are called with consistent (nil) context, the LRU public-key cache is correctly keyed and sized, proto field numbering is stable, and the block-size math checks out against the updated test fixtures.

The implementation is well-structured and the key invariants hold: deterministic signing, cache-assisted verification, correct varint overhead for ML-DSA-65 signatures, and consistent proto/JSON registration. No new correctness or security defects were found beyond the performance and API-shape concerns already raised in earlier review threads.

crypto/mldsa65/key.go warrants a second look for the private-key deserialization cost on every Sign and PubKey call; types/block.go for the const→var change to MaxCommitSigBytes — both tracked in earlier review threads.

Important Files Changed

Filename Overview
crypto/mldsa65/key.go New ML-DSA-65 PrivKey/PubKey implementation with LRU caching verifier; Sign() deserializes the 4032-byte private key on every call (no private-key cache), PubKey() also re-parses on every invocation without populating cachingVerifier.
crypto/mldsa65/key_test.go Comprehensive tests covering sign/verify, deterministic derivation, round-trip bytes, address size, cache hit behavior, and benchmarks for both cached and uncached verification.
crypto/encoding/codec.go Adds unconditional mldsa65 JSON registration and correct PubKeyToProto/PubKeyFromProto/PubKeyFromTypeAndBytes cases; size validation is consistent with other key types.
types/block.go MaxCommitSigBytes changed from const to var to accommodate ML-DSA-65's 3309-byte signatures; the varint overhead constant is correctly updated from 1 to 2 bytes.
types/signable.go MaxSignatureSize extended to include mldsa65.SignatureSize (3309 B) via nested MaxInt; initialization order is safe per Go's dependency-ordered var init.
types/params.go Adds ABCIPubKeyTypeMlDsa65 constant and unconditionally registers mldsa65 in ABCIPubKeyTypesToNames; DefaultValidatorParams remains ed25519-only.
test/e2e/pkg/testnet.go Adds mldsa65 case to keyGenerator.Generate; seed allocated as ed25519.SeedSize (32 B) for all key types including mldsa65 — works today since both are 32 B.
test/e2e/generator/generate.go Adds mldsa65.KeyType to the random keyType uniformChoice; optLarge constant introduced to deduplicate the "large" string.
test/e2e/pkg/testnet_mldsa65_test.go New unit test exercising manifest parsing, key gen, sign/verify, proto round-trip, and ABCIPubKeyTypesToNames registration.
proto/tendermint/crypto/keys.proto Adds mldsa65 as field 4 in the PublicKey oneof; field number is stable and generated pb.go is consistent.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    subgraph KeyGen["ML-DSA-65 Key Generation"]
        A[GenPrivKey / GenPrivKeyFromSeed] -->|circl.GenerateKey| B[circl.PrivateKey]
        B -->|MarshalBinary| C[PrivKey bytes - 4032 B]
    end
    subgraph Sign["Signing - consensus hot path"]
        D[PrivKey.Sign msg] -->|UnmarshalBinary per call| E[circl.PrivateKey]
        E -->|SignTo randomized=false ctx=nil| F[Signature bytes - 3309 B]
    end
    subgraph Verify["Verification - w/ LRU cache"]
        K[PubKey.VerifySignature] --> L{cachingVerifier hit?}
        L -->|Miss - UnmarshalBinary + cache insert| M[circl.PublicKey]
        L -->|Hit| M
        M -->|mldsa65.Verify ctx=nil| N{Valid?}
    end
    subgraph Encoding["Proto / JSON Encoding"]
        O[PubKeyToProto] -->|PublicKey_Mldsa65 field 4| P[pc.PublicKey]
        P -->|PubKeyFromProto| Q[mldsa65.PubKey via NewPubKeyFromBytes]
    end
    C -->|consensus| D
    Q -->|VerifySignature| K
Loading

Reviews (2): Last reviewed commit: "Fix test failure" | Re-trigger Greptile

Comment thread types/block.go Resolved
Comment thread crypto/mldsa65/key.go Resolved
@github-actions

github-actions Bot commented May 19, 2026 •

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow Protobuf Lint / lint (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedMay 27, 2026, 3:37 PM

@Eric-Warehime

Copy link
Copy Markdown
Collaborator Author

@greptile review

@aljo242 aljo242 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did an initial pass and targeted validations:
go test ./crypto/mldsa65 ./crypto/encoding ./types ./test/e2e/pkg -run 'TestMlDsa65Network|TestSignAndVerify|TestDeterministicFromSeed|TestRoundTripBytes|TestAddressIs20Bytes|TestCachingVerifierHitsCache|TestBlockMaxDataBytes|TestBlockMaxDataBytesNoEvidence' -count=1

These checks pass locally.

@Eric-Warehime

Copy link
Copy Markdown
Collaborator Author

Did an initial pass and targeted validations: go test ./crypto/mldsa65 ./crypto/encoding ./types ./test/e2e/pkg -run 'TestMlDsa65Network|TestSignAndVerify|TestDeterministicFromSeed|TestRoundTripBytes|TestAddressIs20Bytes|TestCachingVerifierHitsCache|TestBlockMaxDataBytes|TestBlockMaxDataBytesNoEvidence' -count=1

These checks pass locally.

Two things I’d like maintainer confirmation on before final LGTM:

  1. types.MaxCommitSigBytes changed from const to var (source-level API break for downstream constant expressions). I see the API-breaking changelog note, but this is still a notable compatibility shift.
  2. Changelog has the same ml-dsa entry under both FEATURES and API-BREAKING — likely intentional, but worth confirming desired release-note style.

Thank you for the review Alex-Bot.
The const to var change is intentional--I don't imagine this will break very many people and the fix for it is trivial.
Changelog entry duplication is also intentional.

@aljo242

aljo242 commented May 21, 2026

Copy link
Copy Markdown
Collaborator

ran a local benchmark comparing `Sign()` vs ed25519:

```
BenchmarkMLDSA65Sign ~700 µs/op 77 KB/op
BenchmarkEd25519Sign ~19 µs/op 64 B/op
```

~37x slower because `Sign()` calls `sk.UnmarshalBinary(privKey)` on every call (re-parses the 4032-byte key). `VerifySignature` already has an LRU cache to avoid this — `Sign()` doesn't.

benchmark used:

```go
func BenchmarkMLDSA65Sign(b *testing.B) {
priv, err := mldsa65.GenPrivKey()
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
if _, err := priv.Sign(msg); err != nil {
b.Fatal(err)
}
}
}

func BenchmarkEd25519Sign(b *testing.B) {
priv := ed25519.GenPrivKey()
b.ResetTimer()
for i := 0; i < b.N; i++ {
if _, err := priv.Sign(msg); err != nil {
b.Fatal(err)
}
}
}
```

not a blocker for now, but worth revisiting if this lands on a consensus hot path in production.

Comment thread crypto/mldsa65/key.go Resolved
Comment thread test/e2e/generator/generate.go Resolved
Comment thread types/block.go Resolved
@Eric-Warehime
Eric-Warehime enabled auto-merge May 27, 2026 15:45
@Eric-Warehime
Eric-Warehime added this pull request to the merge queue May 27, 2026
Merged via the queue into main with commit 606b419 May 27, 2026
35 checks passed
@Eric-Warehime
Eric-Warehime deleted the eric/pq branch May 27, 2026 15:55
kevindharmawan pushed a commit to SeeMoReLab/cometbft that referenced this pull request Jul 30, 2026
---
Adds ML-DSA-65 key type as an option for validators looking for
post-quantum secure signing algorithms.

* Uses the `circl` library for all of the crypto.
* Minimally integrates into the places it needs to in comet as an option
for validator keys.
* Adds e2e tests for networks fully based on the new key type

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `CHANGELOG.md`
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
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.

3 participants