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 ¶
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.
type GateAdd ¶
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 ¶
GateCst represents a constant gate within a circuit layer. It directly adds a constant value, defined by Coef, to the output wire.
type GateCustom ¶
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 ¶
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 ¶
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.