Files
Lux Industries Inc 3b6050a4ad feat: canonical PQ profile and proof-policy identifiers v0.1.0
Single source of truth across Go / Solidity / TypeScript for the IDs
that the strict-PQ profile gate consumes. Resolves drift between:

  - papers/pq/pq.tex          STARK_FRI_SHA3_PQ (prose)
  - teleport/contracts        ProofPolicySTARKFRISHA3PQ (deployed)
  - teleport/mpc              POLICY_ID map
  - luxfi/node quasar         Go duplicates

Three subpackages, one set of strings:
  go/                    github.com/luxfi/pq-profile-ids/go
  solidity/              @luxfi/pq-profile-ids  (PQProfileIDs library
                                                 + OnlyStrictPQ modifier)
  ts/                    @luxfi/pq-profile-ids-ts

Cross-language KAT in KAT.md; all three test suites re-derive each
pinned constant from its canonical UTF-8 input.

Decomplected: this repo ONLY pins IDs and exposes the policy-gate.
It does NOT verify proofs. The verifier verifies; the gate decides
admissibility.

Tests: Go 5/5 pass, Solidity 12/12 pass, TS 8/8 pass.
2026-05-13 13:43:38 -07:00

97 lines
2.9 KiB
Go

package profile
import (
"testing"
"golang.org/x/crypto/sha3"
)
// kat re-derives keccak256 of the input string at runtime so a typo in
// one of the pinned hex constants cannot ship undetected. This is the
// Go side of the cross-language KAT in KAT.md.
func kat(t *testing.T, name string, want ID) {
t.Helper()
h := sha3.NewLegacyKeccak256()
h.Write([]byte(name))
var got ID
copy(got[:], h.Sum(nil))
if got != want {
t.Fatalf("kat mismatch for %q\n got: %s\nwant: %s", name, got.Hex(), want.Hex())
}
}
func TestProfileIDs_KAT(t *testing.T) {
kat(t, "PROFILE_CLASSICAL_COMPAT", ProfileClassicalCompat)
kat(t, "PROFILE_QUASAR_STRICT_PQ", ProfileQuasarStrictPQ)
kat(t, "PROFILE_HYBRID", ProfileHybrid)
}
func TestPolicyIDs_KAT(t *testing.T) {
kat(t, "ProofPolicyGroth16BN254", PolicyGroth16BN254)
kat(t, "ProofPolicyPLONKBN254", PolicyPLONKBN254)
kat(t, "ProofPolicyKZGBLS12381", PolicyKZGBLS12381)
kat(t, "ProofPolicySTARKFRISHA3PQ", PolicySTARKFRISHA3)
kat(t, "ProofPolicyMLDSA65FIPS204", PolicyMLDSA65FIPS204)
}
func TestRefuseUnderStrictPQ_ClassicalCompat_AllowsAll(t *testing.T) {
for _, p := range []ID{
PolicyGroth16BN254, PolicyPLONKBN254, PolicyKZGBLS12381,
PolicySTARKFRISHA3, PolicyMLDSA65FIPS204,
} {
if err := RefuseUnderStrictPQ(ProfileClassicalCompat, p); err != nil {
t.Fatalf("classical-compat must allow %s: %v", p.Hex(), err)
}
}
}
func TestRefuseUnderStrictPQ_StrictPQ_RefusesClassical(t *testing.T) {
for _, p := range []ID{PolicyGroth16BN254, PolicyPLONKBN254, PolicyKZGBLS12381} {
err := RefuseUnderStrictPQ(ProfileQuasarStrictPQ, p)
if err == nil {
t.Fatalf("strict-PQ must refuse %s", p.Hex())
}
if _, ok := err.(*VerifierRefusedError); !ok {
t.Fatalf("want *VerifierRefusedError, got %T: %v", err, err)
}
}
}
func TestRefuseUnderStrictPQ_StrictPQ_AllowsPQ(t *testing.T) {
for _, p := range []ID{PolicySTARKFRISHA3, PolicyMLDSA65FIPS204} {
if err := RefuseUnderStrictPQ(ProfileQuasarStrictPQ, p); err != nil {
t.Fatalf("strict-PQ must allow %s: %v", p.Hex(), err)
}
}
}
func TestRefuseUnderStrictPQ_UnknownProfile(t *testing.T) {
var bogus ID
bogus[0] = 0xde
bogus[1] = 0xad
err := RefuseUnderStrictPQ(bogus, PolicySTARKFRISHA3)
if err == nil {
t.Fatal("unknown profile must be rejected")
}
if _, ok := err.(*UnknownProfileError); !ok {
t.Fatalf("want *UnknownProfileError, got %T: %v", err, err)
}
// Hybrid is reserved → also rejected today.
if err := RefuseUnderStrictPQ(ProfileHybrid, PolicySTARKFRISHA3); err == nil {
t.Fatal("hybrid profile is reserved and must reject for now")
}
}
func TestIsPQScheme(t *testing.T) {
for _, ok := range []string{SchemePulsarMLWE, SchemeCoronaRLWE, SchemeDoubleLattice} {
if !IsPQScheme(ok) {
t.Fatalf("IsPQScheme(%q) = false; want true", ok)
}
}
for _, nope := range []string{SchemeECDSAGG18, SchemeECDSACGGMP21, SchemeFROSTRFC9591, "bogus"} {
if IsPQScheme(nope) {
t.Fatalf("IsPQScheme(%q) = true; want false", nope)
}
}
}