Files
corona/threshold/threshold_test.go
T
zeekay 261ad9d290 pulsar: lattice threshold kernel with key-era lifecycle + Pulsar-SHA3 + Nebula binding
Forked from github.com/luxfi/corona @ 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 Corona (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, corona_oracle_v2 KAT —
  all pass.

Honest claim: the crypto primitives are not new (HJKY97,
Desmedt-Jajodia97, Wong-Wang-Wing02, Corona, 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).
2026-03-03 12:00:00 -08:00

151 lines
3.8 KiB
Go

// Copyright (C) 2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package threshold
import (
"testing"
)
func TestGenerateKeys(t *testing.T) {
shares, groupKey, err := GenerateKeys(2, 3, nil)
if err != nil {
t.Fatalf("GenerateKeys failed: %v", err)
}
if len(shares) != 3 {
t.Errorf("expected 3 shares, got %d", len(shares))
}
if groupKey == nil {
t.Fatal("groupKey is nil")
}
if groupKey.A == nil {
t.Error("groupKey.A is nil")
}
if groupKey.BTilde == nil {
t.Error("groupKey.BTilde is nil")
}
for i, share := range shares {
if share.Index != i {
t.Errorf("share %d has index %d", i, share.Index)
}
if share.GroupKey != groupKey {
t.Errorf("share %d has wrong groupKey", i)
}
}
}
func TestThresholdSigningFlow(t *testing.T) {
// Generate 2-of-3 threshold keys
shares, groupKey, err := GenerateKeys(2, 3, nil)
if err != nil {
t.Fatalf("GenerateKeys failed: %v", err)
}
// Create signers for all parties
signers := make([]*Signer, 3)
for i, share := range shares {
signers[i] = NewSigner(share)
}
// Signing parameters
sessionID := 1
prfKey := []byte("test-prf-key-32-bytes-long!!!!!!")
signerIDs := []int{0, 1, 2}
message := "test block hash for consensus"
// Round 1: All parties compute D + MACs
round1Data := make(map[int]*Round1Data)
for _, signer := range signers {
data := signer.Round1(sessionID, prfKey, signerIDs)
round1Data[data.PartyID] = data
t.Logf("Party %d: Round1 complete, D size: %d x %d", data.PartyID, len(data.D), len(data.D[0]))
}
// Round 2: All parties compute z shares
round2Data := make(map[int]*Round2Data)
for _, signer := range signers {
data, err := signer.Round2(sessionID, message, prfKey, signerIDs, round1Data)
if err != nil {
t.Fatalf("Party %d Round2 failed: %v", signer.share.Index, err)
}
round2Data[data.PartyID] = data
t.Logf("Party %d: Round2 complete, z size: %d", data.PartyID, len(data.Z))
}
// Finalize: Any party can aggregate
sig, err := signers[0].Finalize(round2Data)
if err != nil {
t.Fatalf("Finalize failed: %v", err)
}
t.Logf("Signature: C degree=%d, Z size=%d, Delta size=%d", sig.C.N(), len(sig.Z), len(sig.Delta))
// Verify
valid := Verify(groupKey, message, sig)
if !valid {
t.Error("signature verification failed")
}
t.Log("✓ Signature verified successfully")
}
func TestThresholdWrongMessage(t *testing.T) {
shares, groupKey, err := GenerateKeys(2, 3, nil)
if err != nil {
t.Fatalf("GenerateKeys failed: %v", err)
}
signers := make([]*Signer, 3)
for i, share := range shares {
signers[i] = NewSigner(share)
}
sessionID := 1
prfKey := []byte("test-prf-key-32-bytes-long!!!!!!")
signerIDs := []int{0, 1, 2}
message := "original message"
// Round 1
round1Data := make(map[int]*Round1Data)
for _, signer := range signers {
data := signer.Round1(sessionID, prfKey, signerIDs)
round1Data[data.PartyID] = data
}
// Round 2
round2Data := make(map[int]*Round2Data)
for _, signer := range signers {
data, _ := signer.Round2(sessionID, message, prfKey, signerIDs, round1Data)
round2Data[data.PartyID] = data
}
// Finalize
sig, _ := signers[0].Finalize(round2Data)
// Verify with wrong message should fail
valid := Verify(groupKey, "wrong message", sig)
if valid {
t.Error("verification should fail for wrong message")
}
}
func TestInvalidThreshold(t *testing.T) {
// Threshold >= total
_, _, err := GenerateKeys(3, 3, nil)
if err != ErrInvalidThreshold {
t.Errorf("expected ErrInvalidThreshold, got %v", err)
}
// Threshold = 0
_, _, err = GenerateKeys(0, 3, nil)
if err != ErrInvalidThreshold {
t.Errorf("expected ErrInvalidThreshold, got %v", err)
}
// Too few parties
_, _, err = GenerateKeys(1, 1, nil)
if err != ErrInvalidPartyCount {
t.Errorf("expected ErrInvalidPartyCount, got %v", err)
}
}