mirror of
https://github.com/luxfi/corona.git
synced 2026-09-24 00:25:54 +00:00
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).
191 lines
5.5 KiB
Go
191 lines
5.5 KiB
Go
// Copyright (C) 2025-2026, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package reshare
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/ed25519"
|
|
"crypto/rand"
|
|
"testing"
|
|
|
|
"golang.org/x/crypto/curve25519"
|
|
)
|
|
|
|
// TestX25519PairSymmetric — ECDH symmetry: both parties derive the
|
|
// same shared secret. Smoke test that confirms the curve25519
|
|
// integration is wired correctly.
|
|
func TestX25519PairSymmetric(t *testing.T) {
|
|
privA := make([]byte, 32)
|
|
privB := make([]byte, 32)
|
|
if _, err := rand.Read(privA); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := rand.Read(privB); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
pubA, _ := curve25519.X25519(privA, curve25519.Basepoint)
|
|
pubB, _ := curve25519.X25519(privB, curve25519.Basepoint)
|
|
|
|
abShared, err := X25519Pair(privA, pubB)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
baShared, err := X25519Pair(privB, pubA)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !bytes.Equal(abShared, baShared) {
|
|
t.Fatal("X25519 not symmetric")
|
|
}
|
|
}
|
|
|
|
// TestAuthenticatedKex — full authenticated KEX flow, both ends
|
|
// produce the same auth_kex.
|
|
func TestAuthenticatedKex(t *testing.T) {
|
|
// Static (wire) Ed25519 keys for two parties.
|
|
pubA, privA, _ := ed25519.GenerateKey(nil)
|
|
pubB, privB, _ := ed25519.GenerateKey(nil)
|
|
|
|
// Ephemeral X25519 pairs.
|
|
ephPrivA := make([]byte, 32)
|
|
rand.Read(ephPrivA)
|
|
ephPubA, _ := curve25519.X25519(ephPrivA, curve25519.Basepoint)
|
|
|
|
ephPrivB := make([]byte, 32)
|
|
rand.Read(ephPrivB)
|
|
ephPubB, _ := curve25519.X25519(ephPrivB, curve25519.Basepoint)
|
|
|
|
// Common transcript hash (in production this is
|
|
// TranscriptInputs.Hash() — for the test any 32-byte value works).
|
|
thash := [32]byte{0xde, 0xad, 0xbe, 0xef}
|
|
|
|
// Each party signs its own ephemeral.
|
|
sigA := SignEphemeral(privA, ephPubA, thash)
|
|
sigB := SignEphemeral(privB, ephPubB, thash)
|
|
|
|
// Now A computes auth_kex from B's signed ephemeral.
|
|
authKexA, err := AuthenticatedKex(ephPrivA, ephPubB, sigB, pubB, thash, nil)
|
|
if err != nil {
|
|
t.Fatalf("A.AuthenticatedKex: %v", err)
|
|
}
|
|
authKexB, err := AuthenticatedKex(ephPrivB, ephPubA, sigA, pubA, thash, nil)
|
|
if err != nil {
|
|
t.Fatalf("B.AuthenticatedKex: %v", err)
|
|
}
|
|
if !bytes.Equal(authKexA, authKexB) {
|
|
t.Fatal("AuthenticatedKex not symmetric")
|
|
}
|
|
}
|
|
|
|
// TestAuthenticatedKexRejectsBadSig — a tampered signed ephemeral
|
|
// must be rejected (active MITM defense).
|
|
func TestAuthenticatedKexRejectsBadSig(t *testing.T) {
|
|
pubB, privB, _ := ed25519.GenerateKey(nil)
|
|
_ = privB
|
|
|
|
ephPrivA := make([]byte, 32)
|
|
rand.Read(ephPrivA)
|
|
ephPubB := make([]byte, 32)
|
|
rand.Read(ephPubB)
|
|
|
|
thash := [32]byte{0x12}
|
|
// Bogus signature.
|
|
bogus := make([]byte, ed25519.SignatureSize)
|
|
_, err := AuthenticatedKex(ephPrivA, ephPubB, bogus, pubB, thash, nil)
|
|
if err == nil {
|
|
t.Fatal("AuthenticatedKex accepted bogus signature")
|
|
}
|
|
}
|
|
|
|
// TestDeriveSeedsAndMACKeys — both endpoints of a pair derive the
|
|
// same seeds and MAC keys (the canonical-pair ordering ensures this).
|
|
func TestDeriveSeedsAndMACKeys(t *testing.T) {
|
|
const K = 4
|
|
authKex := make(map[[2]int][]byte, K*K)
|
|
for i := 0; i < K; i++ {
|
|
for j := i + 1; j < K; j++ {
|
|
authKex[[2]int{i, j}] = []byte{byte(i*K + j + 1)}
|
|
}
|
|
}
|
|
selfSeeds := make(map[int][]byte, K)
|
|
for i := 0; i < K; i++ {
|
|
selfSeeds[i] = []byte{byte(0xC0 + i)}
|
|
}
|
|
|
|
chainID := []byte("lux-test")
|
|
groupID := []byte("g0")
|
|
const epochID uint64 = 5
|
|
|
|
seeds, err := DeriveSeeds(K, authKex, selfSeeds, chainID, groupID, 0, epochID, nil, 32)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
macs, err := DeriveMACKeys(K, authKex, chainID, groupID, 0, epochID, nil, 32)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Determinism: re-derive and confirm equality.
|
|
seeds2, _ := DeriveSeeds(K, authKex, selfSeeds, chainID, groupID, 0, epochID, nil, 32)
|
|
macs2, _ := DeriveMACKeys(K, authKex, chainID, groupID, 0, epochID, nil, 32)
|
|
for k, v := range seeds {
|
|
if !bytes.Equal(v, seeds2[k]) {
|
|
t.Fatalf("seed at %v non-deterministic", k)
|
|
}
|
|
}
|
|
for k, v := range macs {
|
|
if !bytes.Equal(v, macs2[k]) {
|
|
t.Fatalf("mac at %v non-deterministic", k)
|
|
}
|
|
}
|
|
|
|
// Different epoch → different output.
|
|
seeds3, _ := DeriveSeeds(K, authKex, selfSeeds, chainID, groupID, 0, epochID+1, nil, 32)
|
|
for k, v := range seeds {
|
|
if bytes.Equal(v, seeds3[k]) {
|
|
t.Fatalf("epoch change did not affect derived seed at %v", k)
|
|
}
|
|
}
|
|
|
|
// Different chain ID → different output.
|
|
seeds4, _ := DeriveSeeds(K, authKex, selfSeeds, []byte("different-chain"), groupID, 0, epochID, nil, 32)
|
|
for k, v := range seeds {
|
|
if bytes.Equal(v, seeds4[k]) {
|
|
t.Fatalf("chainID change did not affect derived seed at %v", k)
|
|
}
|
|
}
|
|
|
|
// Diagonal entries (i, i) come from selfSeeds — but only seeds,
|
|
// not MACs (a party doesn't MAC to itself).
|
|
for i := 0; i < K; i++ {
|
|
if _, ok := seeds[[2]int{i, i}]; !ok {
|
|
t.Errorf("missing self-seed for party %d", i)
|
|
}
|
|
if _, ok := macs[[2]int{i, i}]; ok {
|
|
t.Errorf("MAC keys contain a self-pair (i=%d)", i)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestKDFDomainSeparation — same auth_kex, different tags, MUST give
|
|
// different outputs. This is the "PRF and MAC keys are not the same
|
|
// secret" property.
|
|
func TestKDFDomainSeparation(t *testing.T) {
|
|
const K = 2
|
|
authKex := map[[2]int][]byte{
|
|
{0, 1}: []byte("shared-secret-AB"),
|
|
}
|
|
selfSeeds := map[int][]byte{
|
|
0: []byte("self-A"),
|
|
1: []byte("self-B"),
|
|
}
|
|
|
|
seeds, _ := DeriveSeeds(K, authKex, selfSeeds, []byte("c"), []byte("g"), 0, 1, nil, 32)
|
|
macs, _ := DeriveMACKeys(K, authKex, []byte("c"), []byte("g"), 0, 1, nil, 32)
|
|
|
|
if bytes.Equal(seeds[[2]int{0, 1}], macs[[2]int{0, 1}]) {
|
|
t.Fatal("PRF seed and MAC key are equal — KDF tags collide")
|
|
}
|
|
}
|