Files
consensus/protocol/quasar/cert_size_compare_test.go
zeekay 24b7cd2154 consensus: route corona + pulsar through threshold/protocols alias
Replaces every direct import of luxfi/corona/* and luxfi/pulsar/ref/go
in consensus with the canonical luxfi/threshold/protocols/{corona,pulsar}
alias surface. Pure import swap + go.mod bump; no behaviour change.

Files touched (16):

  bench/pq_modes_bench_test.go
  engine/pq/crypto.go
  engine/pq/engine.go
  pkg/wire/policies.go
  protocol/quasar/cert_size_compare_test.go
  protocol/quasar/corona_gob.go
  protocol/quasar/dual_threshold_test.go
  protocol/quasar/epoch.go
  protocol/quasar/epoch_test.go
  protocol/quasar/gpu_accel.go
  protocol/quasar/grouped_threshold.go
  protocol/quasar/quasar.go
  protocol/quasar/types.go
  protocol/quasar/wave_signer.go
  protocol/quasar/wave_signer_test.go
  protocol/quasar/witness.go
  protocol/quasar/witness_pulsar_test.go

Import path swaps:

  luxfi/corona/threshold        -> luxfi/threshold/protocols/corona
  luxfi/corona/keyera           -> luxfi/threshold/protocols/corona/keyera
  luxfi/corona/primitives       -> luxfi/threshold/protocols/corona/primitives
  luxfi/corona/reshare          -> luxfi/threshold/protocols/corona/reshare
  luxfi/corona/sign             -> luxfi/threshold/protocols/corona/sign
  luxfi/corona/gpu              -> luxfi/threshold/protocols/corona/gpu
  luxfi/pulsar/ref/go/pkg/pulsar -> luxfi/threshold/protocols/pulsar

The aliased package name "coronaThreshold" used by quasar / engine/pq /
pkg/wire identifiers is preserved at the call sites (it now refers to
the threshold/protocols/corona alias package). engine/pq/crypto.go is
the only file where the package was bare-imported as `threshold`; that
identifier was renamed to `corona` to match the new alias path.

go.mod:

  - luxfi/threshold bumped to a branch pseudo-version that carries the
    new alias subpackages; will pin to a stable tag once threshold's
    companion commit lands and a release is cut.
  - luxfi/corona and luxfi/pulsar drop to indirect (consensus now
    reaches them only via threshold/protocols).
  - luxfi/math v1.4.0 -> v1.4.1 and luxfi/metric v1.5.0 -> v1.5.7 are
    transitive minimum-version bumps pulled by the new threshold
    requirement; they are no-op for consensus call sites.

Comment-only references to "github.com/luxfi/corona/..." in bls.go,
round_digest.go, reshare_epoch.go, comprehensive_test.go,
engine_test.go, quasar_bench_test.go and config/pq_mode.go are
documentation pointers to where the underlying implementation lives;
they are accurate either way and are left unchanged (out of refactor
scope).

Layering shape after:

  consensus -> threshold/protocols/{corona,pulsar}  (stable alias)
                 |
                 v
              luxfi/corona, luxfi/pulsar  (primitive implementations)

Closes the 22-file layering violation flagged by the 2026-05-31
integration audit. Tests pass: ./engine/pq/..., ./pkg/wire/...,
./protocol/quasar/... (all key cases — TestEpochManager*,
TestRoundSigner*, TestVerifyPQFinality*, TestBLSThreshold*,
TestDualSigningFlow, TestCoronaCertSize* — green; the pre-existing
TestGroupedEpochManager_ParallelKeygen perf-bound flake on slow
machines was reproduced on unmodified main, so it is not a
regression).
2026-05-31 12:39:47 -07:00

87 lines
2.6 KiB
Go

// Copyright (C) 2025, Lux Industries Inc. All rights reserved.
package quasar
import (
"bytes"
"encoding/gob"
"testing"
coronaThreshold "github.com/luxfi/threshold/protocols/corona"
)
// TestCoronaCertSize_BinaryVsGob measures the on-wire Pulsar/Corona
// signature size produced by the native binary encoder vs the legacy gob
// encoder, for the production parameter set (M=8, N=7, LogN=8 -> ring
// degree 256, Q=0x1000000004A01 48-bit prime). Reports per-cert and
// 10K-cert storage so we can see the gob -> native delta.
func TestCoronaCertSize_BinaryVsGob(t *testing.T) {
cfg, err := GenerateDualKeys(2, 3)
if err != nil {
t.Fatalf("GenerateDualKeys: %v", err)
}
signers := make([]*coronaThreshold.Signer, 3)
i := 0
for _, share := range cfg.CoronaShares {
signers[i] = coronaThreshold.NewSigner(share)
i++
}
const sessionID = 1
prfKey := []byte("pulsar-cert-size-prf")
signerIDs := []int{0, 1, 2}
r1 := make(map[int]*coronaThreshold.Round1Data)
for _, s := range signers {
d := s.Round1(sessionID, prfKey, signerIDs)
r1[d.PartyID] = d
}
r2 := make(map[int]*coronaThreshold.Round2Data)
for _, s := range signers {
d, err := s.Round2(sessionID, "test-message", prfKey, signerIDs, r1)
if err != nil {
t.Skipf("Corona Round2 (rejection sampling flake): %v", err)
}
r2[d.PartyID] = d
}
sig, err := signers[0].Finalize(r2)
if err != nil {
t.Fatalf("Finalize: %v", err)
}
binBytes := coronaGobEncode(sig)
var gobBuf bytes.Buffer
if err := gob.NewEncoder(&gobBuf).Encode(sig); err != nil {
t.Fatalf("gob encode: %v", err)
}
gobBytes := gobBuf.Bytes()
binSize := len(binBytes)
gobSize := len(gobBytes)
ratio := float64(gobSize) / float64(binSize)
t.Logf("Pulsar/Corona Signature size (production params M=8 N=7 LogN=8 Q=2^48-ish):")
t.Logf(" Native binary (Poly+Vector MarshalBinary): %7d bytes (%.2f KB)", binSize, float64(binSize)/1024.0)
t.Logf(" Legacy gob (reflection metadata): %7d bytes (%.2f KB)", gobSize, float64(gobSize)/1024.0)
t.Logf(" Bloat: gob/native = %.2fx", ratio)
t.Logf(" 10K certs storage:")
t.Logf(" Native: %.2f MB", float64(binSize)*10000/1024.0/1024.0)
t.Logf(" Gob: %.2f MB", float64(gobSize)*10000/1024.0/1024.0)
// Sanity: roundtrip must be byte-equal
rt, err := coronaGobDecode(binBytes)
if err != nil {
t.Fatalf("native roundtrip decode: %v", err)
}
rtBytes := coronaGobEncode(rt)
if !bytes.Equal(binBytes, rtBytes) {
t.Fatalf("native encode/decode not byte-equal: orig=%d roundtrip=%d", len(binBytes), len(rtBytes))
}
if !coronaThreshold.Verify(cfg.CoronaGroupKey, "test-message", rt) {
t.Fatalf("native-decoded signature failed Verify")
}
}