quasar

package
v1.22.25 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2025 License: BSD-3-Clause Imports: 16 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

View Source
var NewPChain = NewBLS

NewPChain is a deprecated alias for backward compatibility. Deprecated: Use NewBLS instead.

View Source
var NewQuasarHybridConsensus = NewHybrid

NewQuasarHybridConsensus is a deprecated alias for backward compatibility. Deprecated: Use NewHybrid instead.

Functions

func KeyGen

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

KeyGen generates a key pair from seed

func ReleaseHybridSignature added in v1.22.23

func ReleaseHybridSignature(sig *HybridSignature)

ReleaseHybridSignature returns a HybridSignature to the pool. Call this when done with signatures from SignMessage/SignMessageWithContext.

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 BLS added in v1.22.22

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

BLS implements BLS signature aggregation with event horizon finality

func NewBLS added in v1.22.22

func NewBLS(cfg config.Parameters, store dag.Store[VertexID]) *BLS

NewBLS creates a new BLS consensus instance

func (*BLS) ComputeCanonicalOrder added in v1.22.22

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

ComputeCanonicalOrder returns the canonical order of finalized vertices

func (*BLS) EstablishHorizon added in v1.22.22

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

EstablishHorizon creates a new event horizon for BLS finality

func (*BLS) GetLatestHorizon added in v1.22.22

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

GetLatestHorizon returns the most recent event horizon

func (*BLS) Initialize added in v1.22.22

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

Initialize sets up keys for Quasar

func (*BLS) IsBeyondHorizon added in v1.22.22

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

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

func (*BLS) SetFinalizedCallback added in v1.22.22

func (q *BLS) SetFinalizedCallback(cb func(*Block))

SetFinalizedCallback sets the callback for finalized blocks.

type Block added in v1.22.1

type Block struct {
	ID        [32]byte   // Unique block identifier
	ChainID   [32]byte   // Chain this block belongs to
	ChainName string     // Human-readable chain name (e.g., "P-Chain", "X-Chain", "C-Chain")
	Height    uint64     // Block height
	Hash      string     // Block hash
	Timestamp time.Time  // Block timestamp
	Data      []byte     // Block payload data
	Cert      *BlockCert // Quantum certificate (nil if not finalized)
}

Block represents a finalized block in the Quasar consensus. This is the primary block type used throughout the system.

type BlockCert added in v1.22.4

type BlockCert struct {
	BLS      []byte            // BLS aggregate signature
	PQ       []byte            // Post-quantum certificate (ML-DSA/Ringtail)
	Sigs     map[string][]byte // Individual validator signatures
	Epoch    uint64            // Epoch number
	Finality time.Time         // Time of finality
}

BlockCert contains cryptographic certificates for quantum finality.

func (*BlockCert) Verify added in v1.22.4

func (c *BlockCert) Verify(validators []string) bool

Verify checks both BLS and PQ certificates.

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 BLS and PQ certificates for a block.

func (*CertBundle) Verify

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

Verify checks both BLS and PQ certificates.

type ChainBlock added in v1.22.1

type ChainBlock = Block

ChainBlock is an alias for Block for backward compatibility. Deprecated: Use Block instead.

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 Core added in v1.22.4

type Core = Quasar

Core is an alias for the aggregator implementation. Use NewCore() to create a new instance.

type Engine added in v1.22.4

type Engine interface {
	// Start begins the consensus engine
	Start(ctx context.Context) error

	// Stop gracefully shuts down the consensus engine
	Stop() error

	// Submit adds a block to the consensus pipeline
	Submit(block *Block) error

	// Finalized returns a channel of finalized blocks
	Finalized() <-chan *Block

	// IsFinalized checks if a block is finalized
	IsFinalized(blockID [32]byte) bool

	// Stats returns consensus metrics
	Stats() Stats
}

Engine is the main interface for quantum consensus.

func NewEngine added in v1.22.4

func NewEngine(cfg Config) (Engine, error)

NewEngine creates a new Quasar consensus engine.

type Hybrid added in v1.22.22

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

Hybrid implements parallel BLS+Ringtail for PQ-safe consensus

func NewHybrid added in v1.22.22

func NewHybrid(threshold int) (*Hybrid, error)

NewHybrid creates a new hybrid consensus engine

func (*Hybrid) AddValidator added in v1.22.22

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

AddValidator adds a validator to the consensus

func (*Hybrid) AggregateSignatures added in v1.22.22

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

AggregateSignatures aggregates signatures for a message. For long-running operations, use AggregateSignaturesWithContext.

func (*Hybrid) AggregateSignaturesWithContext added in v1.22.23

func (q *Hybrid) AggregateSignaturesWithContext(ctx context.Context, message []byte, signatures []*HybridSignature) (*AggregatedSignature, error)

AggregateSignaturesWithContext aggregates signatures for a message, respecting context cancellation.

func (*Hybrid) GetActiveValidatorCount added in v1.22.22

func (q *Hybrid) GetActiveValidatorCount() int

GetActiveValidatorCount returns the number of active validators

func (*Hybrid) GetThreshold added in v1.22.22

func (q *Hybrid) GetThreshold() int

GetThreshold returns the consensus threshold

func (*Hybrid) SignMessage added in v1.22.22

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

SignMessage signs a message with both BLS and Ringtail. For long-running operations, use SignMessageWithContext.

func (*Hybrid) SignMessageWithContext added in v1.22.23

func (q *Hybrid) SignMessageWithContext(ctx context.Context, validatorID string, message []byte) (*HybridSignature, error)

SignMessageWithContext signs a message with both BLS and Ringtail, respecting context cancellation.

func (*Hybrid) VerifyAggregatedSignature added in v1.22.22

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

VerifyAggregatedSignature verifies an aggregated signature. For long-running operations, use VerifyAggregatedSignatureWithContext.

func (*Hybrid) VerifyAggregatedSignatureWithContext added in v1.22.23

func (q *Hybrid) VerifyAggregatedSignatureWithContext(ctx context.Context, message []byte, aggSig *AggregatedSignature) bool

VerifyAggregatedSignatureWithContext verifies an aggregated signature, respecting context cancellation.

func (*Hybrid) VerifyHybridSignature added in v1.22.22

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

VerifyHybridSignature verifies both BLS and Ringtail signatures. For long-running operations, use VerifyHybridSignatureWithContext.

func (*Hybrid) VerifyHybridSignatureWithContext added in v1.22.23

func (q *Hybrid) VerifyHybridSignatureWithContext(ctx context.Context, message []byte, sig *HybridSignature) bool

VerifyHybridSignatureWithContext verifies both BLS and Ringtail signatures, respecting context cancellation.

type HybridConsensus added in v1.22.4

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

HybridConsensus handles BLS + PQ certificate generation.

func (*HybridConsensus) AddValidator added in v1.22.4

func (h *HybridConsensus) AddValidator(id string, weight int)

AddValidator adds a validator to the consensus.

func (*HybridConsensus) RemoveValidator added in v1.22.4

func (h *HybridConsensus) RemoveValidator(id string)

RemoveValidator removes a validator from the consensus.

type HybridSignature

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

HybridSignature contains both BLS and Ringtail signatures

type PChain added in v1.22.22

type PChain = BLS

PChain is a deprecated alias for backward compatibility. Deprecated: Use BLS instead.

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 = Block

QBlock is an alias for Block for backward compatibility. Deprecated: Use Block instead.

type QuantumBlock added in v1.22.1

type QuantumBlock struct {
	Height        uint64
	SourceBlocks  []*Block
	QuantumHash   string
	BLSSignature  []byte
	RingtailProof []byte // ML-DSA signature
	Timestamp     time.Time
	ValidatorSigs map[string]*HybridSignature
}

QuantumBlock represents a quantum-finalized aggregate block.

type Quasar

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

Quasar is the supermassive black hole at the center of the blockchain galaxy It collects blocks from ALL chains (P, X, C, + any new subnets) and applies quantum consensus External systems (bridges, contracts) can use RPC to add blocks to the event horizon

func NewQuasar added in v1.22.22

func NewQuasar(threshold int) (*Quasar, error)

NewQuasar creates the supermassive black hole at the center of the blockchain galaxy

func (*Quasar) GetMetrics added in v1.22.22

func (q *Quasar) GetMetrics() (processedBlocks, quantumProofs uint64)

GetMetrics returns aggregator metrics

func (*Quasar) GetQuantumHeight added in v1.22.22

func (q *Quasar) GetQuantumHeight() uint64

GetQuantumHeight returns the current quantum finalized height

func (*Quasar) GetRegisteredChains added in v1.22.22

func (q *Quasar) GetRegisteredChains() []string

GetRegisteredChains returns all chains currently in the event horizon

func (*Quasar) ProcessDynamicChains added in v1.22.22

func (q *Quasar) ProcessDynamicChains(ctx context.Context)

ProcessDynamicChains starts processors for all dynamically registered chains This runs alongside the legacy P/X/C chain processors

func (*Quasar) RegisterChain added in v1.22.22

func (q *Quasar) RegisterChain(chainName string) error

RegisterChain dynamically registers a new chain/subnet for automatic quantum security All new subnets are automatically protected by the event horizon

func (*Quasar) Start added in v1.22.1

func (q *Quasar) Start(ctx context.Context) error

Start begins drawing blocks into the Quasar's gravitational pull

func (*Quasar) SubmitBlock added in v1.22.22

func (q *Quasar) SubmitBlock(block *ChainBlock) error

SubmitBlock is the universal RPC endpoint for ANY chain/contract to add blocks External systems (bridge, contracts) use this to enter the event horizon

func (*Quasar) SubmitCChainBlock added in v1.22.22

func (q *Quasar) SubmitCChainBlock(block *ChainBlock)

SubmitCChainBlock submits a C-Chain block for quantum consensus

func (*Quasar) SubmitPChainBlock added in v1.22.22

func (q *Quasar) SubmitPChainBlock(block *ChainBlock)

SubmitPChainBlock submits a P-Chain block for quantum consensus

func (*Quasar) SubmitXChainBlock added in v1.22.22

func (q *Quasar) SubmitXChainBlock(block *ChainBlock)

SubmitXChainBlock submits an X-Chain block for quantum consensus

func (*Quasar) VerifyQuantumFinality added in v1.22.22

func (q *Quasar) VerifyQuantumFinality(blockHash string) bool

VerifyQuantumFinality checks if a block has quantum finality. For context-aware verification, use VerifyQuantumFinalityWithContext.

func (*Quasar) VerifyQuantumFinalityWithContext added in v1.22.23

func (q *Quasar) VerifyQuantumFinalityWithContext(ctx context.Context, blockHash string) bool

VerifyQuantumFinalityWithContext checks if a block has quantum finality, respecting context cancellation.

type QuasarCore added in v1.22.1

type QuasarCore = Quasar

QuasarCore is a deprecated alias for backward compatibility. Deprecated: Use Quasar or Core instead.

type QuasarHybridConsensus

type QuasarHybridConsensus = Hybrid

QuasarHybridConsensus is a deprecated alias for backward compatibility. Deprecated: Use Hybrid instead.

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 Stats added in v1.22.4

type Stats struct {
	Height          uint64        // Current finalized height
	ProcessedBlocks uint64        // Total blocks processed
	FinalizedBlocks uint64        // Total blocks finalized
	PendingBlocks   int           // Blocks awaiting finality
	Validators      int           // Active validator count
	Uptime          time.Duration // Time since start
}

Stats contains consensus metrics.

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 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