layered

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package layered defines the structures and functions necessary for creating and manipulating layered circuits within the ExpanderCompilerCollection compiler. A layered circuit is a representation of a computation that is divided into a sequence of discrete layers, facilitating certain types of optimizations and parallel computations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Validate

func Validate(rc *RootCircuit) error

Validate checks the structural integrity of a RootCircuit. It ensures that all components and connections within the circuit adhere to the expected format and constraints of a layered circuit.

func ValidateInitialized

func ValidateInitialized(rc *RootCircuit) error

ValidateInitialized verifies that all wire inputs in a RootCircuit have been properly initialized. An uninitialized wire input would indicate an incomplete or improperly constructed circuit.

Types

type Allocation

type Allocation struct {
	InputOffset  uint64
	OutputOffset uint64
}

Allocation defines the input and output offsets for a subcircuit call. These offsets determine where the subcircuit's inputs and outputs are positioned within the larger circuit context.

type Circuit

type Circuit struct {
	InputLen    uint64
	OutputLen   uint64
	SubCircuits []SubCircuit
	Mul         []GateMul
	Add         []GateAdd
	Cst         []GateCst
	Custom      []GateCustom
}

Circuit represents a single segment within a layered circuit. It contains the length of inputs and outputs, a list of subcircuits that can be called within this segment, and the gates that perform various arithmetic operations within the segment.

func (*Circuit) Print

func (c *Circuit) Print()

Print outputs the entire circuit structure to the console for debugging purposes. It provides a human-readable representation of the circuit's layers, gates, and subcircuits, along with their interconnections.

type GateAdd

type GateAdd struct {
	In   uint64
	Out  uint64
	Coef *big.Int
}

GateAdd represents an addition gate within a circuit layer. It specifies the input and output wire indices, and the coefficient to be multiplied with the input before being added to the output.

type GateCst

type GateCst struct {
	Out  uint64
	Coef *big.Int
}

GateCst represents a constant gate within a circuit layer. It directly adds a constant value, defined by Coef, to the output wire.

type GateCustom

type GateCustom struct {
	GateType uint64
	In       []uint64
	Out      uint64
	Coef     *big.Int
}

GateCustom represents a custom gate within a circuit layer. It takes several inputs, and produces an output value. The output wire must be dedicated to this gate.

type GateMul

type GateMul struct {
	In0  uint64
	In1  uint64
	Out  uint64
	Coef *big.Int
}

GateMul represents a multiplication gate within a circuit layer. It specifies two input wire indices and an output wire index, along with a coefficient. The product of the inputs and the coefficient is added to the output.

type RootCircuit

type RootCircuit struct {
	Circuits []*Circuit
	Layers   []uint64
	Field    *big.Int
}

RootCircuit defines a multi-layered circuit. The Layers field specifies the indices of each layer, which are referenced through the Circuits array. Field denotes the mathematical field over which the circuit operations are carried out.

func DeserializeRootCircuit

func DeserializeRootCircuit(buf []byte) *RootCircuit

func Optimize

func Optimize(rc *RootCircuit) *RootCircuit

Optimize applies various optimization strategies to a RootCircuit to reduce its complexity and improve computational efficiency.

func (*RootCircuit) GetStats

func (rc *RootCircuit) GetStats() Stats

GetStats collects and returns statistical information about a RootCircuit, such as the number of layers, circuits, and different types of gates before and after expansion.

func (*RootCircuit) Print

func (rc *RootCircuit) Print()

Print outputs the entire multi-layered circuit structure to the console for debugging purposes. It provides a detailed view of the circuit's construction, including all gates and their connections across layers.

func (*RootCircuit) Serialize

func (rc *RootCircuit) Serialize() []byte

Serialize converts a RootCircuit into a byte array for storage or transmission.

type Stats

type Stats struct {
	// number of layers in the final circuit
	NbLayer int
	// number of circuits (or, segments)
	NbCircuit int
	// number of used input variables
	NbInput int
	// number of mul/add/cst gates in all circuits (unexpanded)
	NbTotMul    int
	NbTotAdd    int
	NbTotCst    int
	NbTotCustom map[uint64]int
	// number of mul/add/cst gates in expanded form of all layers
	NbExpandedMul    int
	NbExpandedAdd    int
	NbExpandedCst    int
	NbExpandedCustom map[uint64]int
	// number of total gates in the final circuit (except input gates)
	NbTotGates int
	// number of actually used gates used in the final circuit
	NbUsedGates int
	// total cost according to some formula
	TotalCost int
}

type SubCircuit

type SubCircuit struct {
	Id          uint64
	Allocations []Allocation
}

SubCircuit represents a subcircuit that is used within a Circuit. It has the identifier of the subcircuit (indexed in RootCircuit.Circuits) and a list of allocations that define the input and output connections to the subcircuit.

Jump to

Keyboard shortcuts

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