mirror of
https://github.com/luxfi/pulsar.git
synced 2026-09-24 00:25:52 +00:00
Forked from github.com/luxfi/ringtail @ d09b2c2. Pulsar inherits the
2-round signing math byte-equal but adds blockchain-grade key
lifecycle and a SHA3-based domain-separated hash profile for
permissionless validator-set rotation.
Inherits from upstream Ringtail (byte-equal):
- Sign1/Sign2/Combine 2-round signing math
- Lattice ring R_q = Z_q[X]/(X^256+1), q = 0x1000000004A01
- Module-LWE / Module-SIS hardness
- NTT, Discrete-Gaussian Ziggurat, MAC layer
Replaces from upstream:
- Broken Feldman-style DKG (pseudoinverse-recoverable). Replaced
with: (a) one-time foundation MPC ceremony / trusted-dealer
Bootstrap; (b) Pedersen DKG over R_q (research, dkg2/) hiding
under MLWE on B / binding under MSIS on [A | B].
- Trusted-dealer-per-epoch lifecycle (wrong shape for permissionless
rotation). Replaced with Verifiable Secret Resharing (VSR) every
epoch under the persistent group public key.
Key-era lifecycle (KeyEraID / Generation / RollbackFrom):
- KeyEraID bumps only at Reanchor (rare governance event)
- Generation bumps every Refresh / Reshare under the same GroupKey
- RollbackFrom records prior generation reverted from (0 = forward)
- Activation cert (QUASAR-PULSAR-ACTIVATE-v1) gates new generations
under the unchanged GroupKey
Pulsar-SHA3 hash profile (NIST FIPS 202 / SP 800-185):
- Hc: cSHAKE256("PULSAR-HC-v1", transcript) → challenge
- Hu: cSHAKE256("PULSAR-HU-v1", transcript) → XOF stream
- TranscriptHash: TupleHash256("PULSAR-TRANSCRIPT-v1", parts...)
- PRF: KMAC256(key, msg, "PULSAR-PRF-v1")
- MAC: KMAC256(key, msg, "PULSAR-MAC-v1")
- Pairwise: KMAC256(kex, encode(...), "PULSAR-PAIRWISE-v1")
- Default suite is Pulsar-SHA3; Pulsar-BLAKE3 retained as optional
non-normative fast profile. HashSuiteID is bound into transcripts.
- Implementation at pulsar/hash/ with HashSuite interface.
- All KATs regenerated under SHA3 profile; vectors in
luxcpp/crypto/pulsar/test/kat/.
Nebula root binding (TranscriptInputs + ActivationMessage canonical
bytes, all bound under TupleHash256):
chain_id, network_id, group_id,
key_era_id, old_generation, new_generation,
old_epoch_id, new_epoch_id,
old_set_hash, new_set_hash,
threshold_old, threshold_new,
group_public_key_hash,
nebula_root,
hash_suite_id,
implementation_version,
variant.
Packages:
primitives/ Shamir over R_q, Lagrange, hash helpers
sign/ 2-round sign math (byte-equal upstream)
threshold/ GroupKey, KeyShare, Signer types
reshare/ VSR kernel — Refresh (HJKY97 zero-poly), Reshare
(Desmedt-Jajodia), commit (Pedersen R_q), complaint,
transcript, pairwise KEX, activation cert
hash/ HashSuite interface; PulsarSHA3 (default), PulsarBLAKE3
dkg2/ Pedersen DKG over R_q (research, reference only)
keyera/ Lifecycle wrapper: Bootstrap → Reshare → Reanchor
papers/ LP-073-pulsar paper (sections + bibliography)
cmd/*_oracle/ KAT generators (Go ↔ C++ byte-equal validation)
DESIGN.md is the single source of truth:
- The Pulsar metaphor (rotating beam over persistent body)
- Vocabulary stack per LP-105: Nebula / Photon / Lumen / Beam /
Pulsar / Pulse / Prism / Horizon / Quasar
- Pulsar ≠ Lumen (PQ stream is separate, planned)
- Pulsar / Lens / LSS three-layer architecture
- Bootstrap Dealer vs Signature Coordinator
- No-slashing failure ladder (timeout → retry → rollback → reanchor)
- MVP VSR vs Robust VSR phasing
- Borrowed-brand terms ("X-Wing" used casually) replaced with
"hybrid KEM" / "Hybrid Lumen Handshake"; X-Wing cited only as
the IETF combiner primitive name where exact reference matters.
Tests: full suite green
hash 5+/5+, keyera 5/5, reshare 45+/45+, threshold, sign, dkg,
dkg2, primitives, networking, utils, ringtail_oracle_v2 KAT —
all pass.
Honest claim: the crypto primitives are not new (HJKY97,
Desmedt-Jajodia97, Wong-Wang-Wing02, Ringtail, Hermine, Threshold
Raccoon all exist). The novel contribution is the systems
composition: a permissionless-consensus deployment architecture that
turns static two-round PQ threshold signatures into a dynamic,
leaderless, validator-rotation-tolerant finality layer.
Companion docs: papers/lp-073-pulsar/ (academic paper); LP-073 +
LP-103 + LP-105 in github.com/luxfi/lps; threshold/protocols/lss/
lss_pulsar.go (LSS adapter wrapping this kernel).
209 lines
6.3 KiB
Go
209 lines
6.3 KiB
Go
// Copyright (C) 2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
// Package cli provides the "rt" (ringtail) subcommand for the lux CLI.
|
|
// It wires directly to the github.com/luxfi/pulsar/threshold and
|
|
// github.com/luxfi/pulsar/dkg packages.
|
|
package cli
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/luxfi/pulsar/threshold"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// NewCmd returns the "rt" command tree for the lux CLI.
|
|
func NewCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "rt",
|
|
Aliases: []string{"ringtail"},
|
|
Short: "Ringtail threshold signing",
|
|
Long: `The rt (ringtail) command provides tools for Ringtail threshold signing,
|
|
a post-quantum threshold signature scheme using Ring-LWE.
|
|
|
|
Ringtail is part of the triple consensus (BLS + Ringtail + ML-DSA) used
|
|
by Lux validators. It provides threshold signatures where t-of-n parties
|
|
can cooperatively produce a valid signature without reconstructing the
|
|
full private key.
|
|
|
|
KEY PROPERTIES:
|
|
|
|
- Post-quantum secure (lattice-based)
|
|
- t-of-n threshold without trusted dealer (via DKG)
|
|
- Proactive resharing for key rotation
|
|
- Compatible with QuasarCert attestations`,
|
|
RunE: func(cmd *cobra.Command, _ []string) error {
|
|
return cmd.Help()
|
|
},
|
|
}
|
|
|
|
cmd.AddCommand(newKeygenCmd())
|
|
cmd.AddCommand(newSignCmd())
|
|
cmd.AddCommand(newVerifyCmd())
|
|
cmd.AddCommand(newReshareCmd())
|
|
|
|
return cmd
|
|
}
|
|
|
|
// keygenOutput is the JSON structure written by keygen.
|
|
type keygenOutput struct {
|
|
Threshold int `json:"threshold"`
|
|
Parties int `json:"parties"`
|
|
GroupKey []byte `json:"group_key"`
|
|
}
|
|
|
|
// shareOutput is the JSON structure for each key share.
|
|
type shareOutput struct {
|
|
Index int `json:"index"`
|
|
GroupKey []byte `json:"group_key"`
|
|
}
|
|
|
|
func newKeygenCmd() *cobra.Command {
|
|
var (
|
|
t int
|
|
n int
|
|
output string
|
|
)
|
|
cmd := &cobra.Command{
|
|
Use: "keygen",
|
|
Short: "Generate threshold key shares",
|
|
Long: `Generate t-of-n threshold key shares for Ringtail signing.
|
|
|
|
Examples:
|
|
lux rt keygen --threshold 3 --parties 5 --output ./shares/
|
|
lux rt keygen --threshold 2 --parties 3`,
|
|
RunE: func(_ *cobra.Command, _ []string) error {
|
|
if t < 1 {
|
|
return fmt.Errorf("--threshold must be >= 1")
|
|
}
|
|
if n < 2 {
|
|
return fmt.Errorf("--parties must be >= 2")
|
|
}
|
|
if t >= n {
|
|
return fmt.Errorf("--threshold must be < --parties")
|
|
}
|
|
|
|
fmt.Fprintf(os.Stderr, "Generating %d-of-%d threshold key shares...\n", t, n)
|
|
|
|
shares, groupKey, err := threshold.GenerateKeys(t, n, rand.Reader)
|
|
if err != nil {
|
|
return fmt.Errorf("generate keys: %w", err)
|
|
}
|
|
|
|
if output == "" {
|
|
output = "."
|
|
}
|
|
if err := os.MkdirAll(output, 0o750); err != nil {
|
|
return fmt.Errorf("create output dir: %w", err)
|
|
}
|
|
|
|
gkBytes := groupKey.Bytes()
|
|
|
|
// Write group key info
|
|
info := keygenOutput{
|
|
Threshold: t,
|
|
Parties: n,
|
|
GroupKey: gkBytes,
|
|
}
|
|
infoData, err := json.MarshalIndent(info, "", " ")
|
|
if err != nil {
|
|
return fmt.Errorf("marshal group info: %w", err)
|
|
}
|
|
infoPath := output + "/group.json"
|
|
if err := os.WriteFile(infoPath, infoData, 0o644); err != nil {
|
|
return fmt.Errorf("write group info: %w", err)
|
|
}
|
|
|
|
// Write each share
|
|
for i, share := range shares {
|
|
so := shareOutput{
|
|
Index: share.Index,
|
|
GroupKey: gkBytes,
|
|
}
|
|
data, err := json.MarshalIndent(so, "", " ")
|
|
if err != nil {
|
|
return fmt.Errorf("marshal share %d: %w", i, err)
|
|
}
|
|
path := fmt.Sprintf("%s/share-%d.json", output, i)
|
|
if err := os.WriteFile(path, data, 0o600); err != nil {
|
|
return fmt.Errorf("write share %d: %w", i, err)
|
|
}
|
|
}
|
|
|
|
fmt.Fprintf(os.Stderr, "Generated %d shares -> %s/\n", len(shares), output)
|
|
fmt.Fprintf(os.Stderr, "Group key: %s\n", infoPath)
|
|
return nil
|
|
},
|
|
}
|
|
cmd.Flags().IntVar(&t, "threshold", 0, "Signing threshold (t)")
|
|
cmd.Flags().IntVar(&n, "parties", 0, "Total number of parties (n)")
|
|
cmd.Flags().StringVar(&output, "output", "", "Output directory for key shares (default: current dir)")
|
|
return cmd
|
|
}
|
|
|
|
func newSignCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "sign",
|
|
Short: "Initiate threshold signing",
|
|
Long: `Initiate a Ringtail threshold signing session.
|
|
|
|
Requires t-of-n key holders to participate in the 2-round signing protocol:
|
|
Round 1: Each party broadcasts D matrix + MACs
|
|
Round 2: Each party broadcasts z share
|
|
Finalize: Any party aggregates into final signature
|
|
|
|
Examples:
|
|
lux rt sign --message "hello" --share ./shares/share-0.json
|
|
lux rt sign --tx-file unsigned.tx --share ./shares/share-0.json`,
|
|
RunE: func(_ *cobra.Command, _ []string) error {
|
|
return fmt.Errorf("interactive threshold signing requires a network session; use the SDK for programmatic signing")
|
|
},
|
|
}
|
|
cmd.Flags().String("message", "", "Message to sign (hex or string)")
|
|
cmd.Flags().String("share", "", "Path to key share file")
|
|
return cmd
|
|
}
|
|
|
|
func newVerifyCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "verify",
|
|
Short: "Verify a Ringtail signature",
|
|
Long: `Verify a Ringtail threshold signature against the group public key.
|
|
|
|
Examples:
|
|
lux rt verify --signature sig.json --message "hello" --group-key group.json`,
|
|
RunE: func(_ *cobra.Command, _ []string) error {
|
|
return fmt.Errorf("signature verification requires serialized signature format; use the SDK for programmatic verification")
|
|
},
|
|
}
|
|
cmd.Flags().String("signature", "", "Path to signature file")
|
|
cmd.Flags().String("message", "", "Message that was signed")
|
|
cmd.Flags().String("group-key", "", "Path to group key file")
|
|
return cmd
|
|
}
|
|
|
|
func newReshareCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "reshare",
|
|
Short: "Reshare keys to new committee",
|
|
Long: `Reshare existing key shares to a new committee configuration.
|
|
|
|
Proactive resharing allows rotating key shares without changing the
|
|
group public key. Used for committee membership changes.
|
|
|
|
Examples:
|
|
lux rt reshare --old-shares ./old/ --new-threshold 3 --new-parties 7`,
|
|
RunE: func(_ *cobra.Command, _ []string) error {
|
|
return fmt.Errorf("resharing requires coordinated multi-party protocol; use the SDK for programmatic resharing")
|
|
},
|
|
}
|
|
cmd.Flags().String("old-shares", "", "Directory containing old key shares")
|
|
cmd.Flags().Int("new-threshold", 0, "New signing threshold")
|
|
cmd.Flags().Int("new-parties", 0, "New total number of parties")
|
|
return cmd
|
|
}
|