quasar

package
v1.19.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2025 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package quasar provides post-quantum overlay: dual BLS + ring certificates.

Quasar prepares for the quantum age by running both BLS (fast, classical) and ring signatures (quantum-safe, larger) in parallel. The system can seamlessly transition when quantum computers arrive, making the consensus future-proof. Quasars are among the most energetic objects in the universe.

Package ringtail provides post-quantum cryptographic primitives for the Lux consensus. This is a stub implementation that forwards to the actual implementation in github.com/luxfi/crypto/ringtail.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCertificate  = errors.New("invalid certificate")
	ErrMissingCertificate  = errors.New("missing certificate")
	ErrCertificateMismatch = errors.New("certificate mismatch")
)

Error variables

View Source
var DefaultConfig = Config{QThreshold: 3, QuasarTimeout: 30}

DefaultConfig for quasar protocol

Functions

func KeyGen

func KeyGen(seed []byte) ([]byte, []byte, error)

KeyGen generates a key pair from seed

func Verify

func Verify(pk []byte, msg []byte, cert []byte) bool

Verify verifies a certificate

func VerifyShare

func VerifyShare(pk []byte, msg []byte, share []byte) bool

VerifyShare verifies a share signature

Types

type AggregatedSignature

type AggregatedSignature struct {
	BLSAggregated []byte
	RingtailSigs  []RingtailSignature
	SignerCount   int
}

AggregatedSignature contains aggregated BLS and individual Ringtail signatures

type Bundle

type Bundle struct {
	Epoch   uint64
	Root    []byte
	BLSAgg  []byte
	PQBatch []byte
	Binding []byte
}

Bundle represents a finalized epoch bundle

type Cert

type Cert = []byte

Type aliases for cleaner API

func Aggregate

func Aggregate(shares []Share) (Cert, error)

Aggregate aggregates shares into a certificate

type CertBundle

type CertBundle struct {
	BLSAgg []byte // BLS aggregate signature
	PQCert []byte // Post-quantum certificate
}

CertBundle contains both classical and quantum certificates

func (*CertBundle) Verify

func (c *CertBundle) Verify(_ []string) bool

Verify checks both BLS and PQ certificates

type Client

type Client interface {
	SubmitCheckpoint(epoch uint64, root []byte, attest []byte) error
	FetchBundle(epoch uint64) (Bundle, error)
	Verify(Bundle) bool
}

Client interface for Quasar operations

type CompressedWitness

type CompressedWitness struct {
	CommitmentAndProof []byte // Combined commitment + proof
	Metadata           uint64 // Packed height + timestamp
	Validators         uint32 // Validator bitfield (up to 32 validators)
}

CompressedWitness creates an even smaller witness for network transmission

func (*CompressedWitness) Size

func (c *CompressedWitness) Size() int

Size returns size of compressed witness

type Config

type Config struct {
	QThreshold    int
	QuasarTimeout int
}

Config represents quasar protocol configuration

type HybridSignature

type HybridSignature struct {
	BLS         []byte
	Ringtail    []byte
	ValidatorID string
}

HybridSignature contains both BLS and Ringtail signatures

type Precomp

type Precomp = []byte

Type aliases for cleaner API

func Precompute

func Precompute(sk []byte) (Precomp, error)

Precompute generates a precomputed share

type PublicKey

type PublicKey = []byte

Type aliases for cleaner API

type QBlock

type QBlock struct {
	Height    uint64
	Hash      string
	Timestamp time.Time
	Cert      *CertBundle
}

QBlock represents a quantum-finalized block

type Quasar

type Quasar struct {
	// Configuration
	K     int
	Alpha float64
	Beta  uint32
	// contains filtered or unexported fields
}

Quasar implements P-Chain post-quantum consensus with event horizon finality

func New

func New(cfg config.Parameters, store dag.Store[VertexID]) *Quasar

New creates a new Quasar P-Chain instance

func (*Quasar) ComputeCanonicalOrder

func (q *Quasar) ComputeCanonicalOrder() []VertexID

ComputeCanonicalOrder returns the canonical order of finalized vertices

func (*Quasar) EstablishHorizon

func (q *Quasar) EstablishHorizon(ctx context.Context, checkpoint VertexID, validators []string) (*dag.EventHorizon[VertexID], error)

EstablishHorizon creates a new event horizon for P-Chain finality

func (*Quasar) GetLatestHorizon

func (q *Quasar) GetLatestHorizon() *dag.EventHorizon[VertexID]

GetLatestHorizon returns the most recent event horizon

func (*Quasar) Initialize

func (q *Quasar) Initialize(_ context.Context, blsKey, pqKey []byte) error

Initialize sets up keys for Quasar

func (*Quasar) IsBeyondHorizon

func (q *Quasar) IsBeyondHorizon(vertex VertexID) bool

IsBeyondHorizon checks if a vertex is beyond the event horizon (finalized)

func (*Quasar) SetFinalizedCallback

func (q *Quasar) SetFinalizedCallback(cb func(QBlock))

SetFinalizedCallback sets the callback for finalized blocks

type QuasarHybridConsensus

type QuasarHybridConsensus struct {
	// contains filtered or unexported fields
}

QuasarHybridConsensus implements parallel BLS+Ringtail for PQ-safe consensus

func NewQuasarHybridConsensus

func NewQuasarHybridConsensus(threshold int) (*QuasarHybridConsensus, error)

NewQuasarHybridConsensus creates a new hybrid consensus engine

func (*QuasarHybridConsensus) AddValidator

func (q *QuasarHybridConsensus) AddValidator(id string, weight uint64) error

AddValidator adds a validator to the consensus

func (*QuasarHybridConsensus) AggregateSignatures

func (q *QuasarHybridConsensus) AggregateSignatures(message []byte, signatures []*HybridSignature) (*AggregatedSignature, error)

AggregateSignatures aggregates signatures for a message

func (*QuasarHybridConsensus) GetActiveValidatorCount

func (q *QuasarHybridConsensus) GetActiveValidatorCount() int

GetActiveValidatorCount returns the number of active validators

func (*QuasarHybridConsensus) GetThreshold

func (q *QuasarHybridConsensus) GetThreshold() int

GetThreshold returns the consensus threshold

func (*QuasarHybridConsensus) SignMessage

func (q *QuasarHybridConsensus) SignMessage(validatorID string, message []byte) (*HybridSignature, error)

SignMessage signs a message with both BLS and Ringtail

func (*QuasarHybridConsensus) VerifyAggregatedSignature

func (q *QuasarHybridConsensus) VerifyAggregatedSignature(message []byte, aggSig *AggregatedSignature) bool

VerifyAggregatedSignature verifies an aggregated signature

func (*QuasarHybridConsensus) VerifyHybridSignature

func (q *QuasarHybridConsensus) VerifyHybridSignature(message []byte, sig *HybridSignature) bool

VerifyHybridSignature verifies both BLS and Ringtail signatures

type RingtailEngine

type RingtailEngine interface {
	// Initialize the engine with security parameters
	Initialize(level SecurityLevel) error

	// Sign a message with the secret key
	Sign(msg []byte, sk SecretKey) (Signature, error)

	// Verify a signature
	Verify(msg []byte, sig Signature, pk PublicKey) bool

	// Generate a new key pair
	GenerateKeyPair() (SecretKey, PublicKey, error)

	// KEM operations for post-quantum key exchange
	Encapsulate(pk PublicKey) ([]byte, []byte, error)
	Decapsulate(ct []byte, sk SecretKey) ([]byte, error)

	// Shared secret operations
	CombineSharedSecrets(ss1, ss2 []byte) []byte
	DeriveKey(secret []byte, length int) []byte
}

RingtailEngine represents the post-quantum consensus engine

func NewRingtail

func NewRingtail() RingtailEngine

NewRingtail creates a new ringtail engine

type RingtailKeyPair

type RingtailKeyPair struct {
	PrivateKey *mldsa.PrivateKey
	PublicKey  *mldsa.PublicKey
}

RingtailKeyPair holds a post-quantum key pair

type RingtailPQ

type RingtailPQ struct {
	// contains filtered or unexported fields
}

RingtailPQ provides real post-quantum signatures using ML-DSA

type RingtailSignature

type RingtailSignature struct {
	Signature   []byte
	PublicKey   []byte
	ValidatorID string
}

RingtailSignature represents a post-quantum signature

type SecretKey

type SecretKey = []byte

Type aliases for cleaner API

type SecurityLevel

type SecurityLevel int

SecurityLevel represents the post-quantum security level

const (
	SecurityLow    SecurityLevel = 0
	SecurityMedium SecurityLevel = 1
	SecurityHigh   SecurityLevel = 2
)

type Share

type Share = []byte

Type aliases for cleaner API

func QuickSign

func QuickSign(precomp Precomp, msg []byte) (Share, error)

QuickSign signs using a precomputed share

type Signature

type Signature = []byte // Alias for Share or Cert depending on context

Type aliases for cleaner API

type Validator

type Validator struct {
	ID          string
	BLSPubKey   *bls.PublicKey
	RingtailPub *mldsa.PublicKey
	Weight      uint64
	Active      bool
}

Validator represents a consensus validator

type VerkleWitness

type VerkleWitness struct {
	// contains filtered or unexported fields
}

VerkleWitness provides hyper-efficient state verification Assumes every block is PQ-final via BLS+Ringtail threshold

func NewVerkleWitness

func NewVerkleWitness(threshold int) *VerkleWitness

NewVerkleWitness creates a lightweight Verkle witness verifier

func (*VerkleWitness) BatchVerify

func (v *VerkleWitness) BatchVerify(witnesses []*WitnessProof) error

BatchVerify verifies multiple witnesses in parallel (hyper-efficient)

func (*VerkleWitness) CreateWitness

func (v *VerkleWitness) CreateWitness(
	stateRoot []byte,
	blsAgg *bls.Signature,
	ringtailSigners []bool,
	height uint64,
) (*WitnessProof, error)

CreateWitness creates a minimal witness for a state transition

func (*VerkleWitness) GetCachedWitness

func (v *VerkleWitness) GetCachedWitness(stateRoot []byte) (*WitnessProof, bool)

GetCachedWitness retrieves a cached witness if available

func (*VerkleWitness) VerifyCompressed

func (v *VerkleWitness) VerifyCompressed(cw *CompressedWitness) error

VerifyCompressed verifies a compressed witness (ultra-fast)

func (*VerkleWitness) VerifyStateTransition

func (v *VerkleWitness) VerifyStateTransition(witness *WitnessProof) error

VerifyStateTransition verifies state transition with minimal overhead Assumes PQ finality via BLS+Ringtail threshold already met

type VertexID

type VertexID [32]byte

VertexID represents a P-Chain vertex identifier

type WitnessProof

type WitnessProof struct {
	// Verkle proof components
	Commitment   []byte // 32 bytes banderwagon point
	Path         []byte // Compressed path in tree
	OpeningProof []byte // IPA opening proof

	// PQ finality certificate (lightweight)
	BLSAggregate []byte // Aggregated BLS signature
	RingtailBits []byte // Bitfield of Ringtail signers
	ValidatorSet []byte // Compressed validator set hash

	// Block metadata
	BlockHeight uint64
	StateRoot   []byte
	Timestamp   uint64
}

WitnessProof contains the minimal proof for state verification

func (*WitnessProof) Compress

func (w *WitnessProof) Compress() *CompressedWitness

Compress creates a compressed witness (< 200 bytes)

func (*WitnessProof) IsLightweight

func (w *WitnessProof) IsLightweight() bool

IsLightweight checks if witness is under 1KB (hyper-efficient)

func (*WitnessProof) Size

func (w *WitnessProof) Size() int

WitnessSize returns the size of a witness in bytes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL