layered

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2025 License: AGPL-3.0 Imports: 6 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

View Source
const MAGIC = 3914834606642317635

Variables

This section is empty.

Functions

func DetectFieldIdFromFile

func DetectFieldIdFromFile(fn string) uint64

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 Gate

type Gate interface {
	InWires() []uint64
	OutWire() uint64
	CoefValue() *big.Int
}

A generic gate interface

type GateAdd

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

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.

func (GateAdd) CoefValue

func (g GateAdd) CoefValue() *big.Int

Coef value of add gate

func (GateAdd) InWires

func (g GateAdd) InWires() []uint64

Input wire of mul gate

func (GateAdd) OutWire

func (g GateAdd) OutWire() uint64

Output wire of add gate

type GateCst

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

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

func (GateCst) CoefValue

func (g GateCst) CoefValue() *big.Int

coefficient value of const gate

func (GateCst) InWires

func (g GateCst) InWires() []uint64

Input wires of const gate

func (GateCst) OutWire

func (g GateCst) OutWire() uint64

Output wire of const gate

type GateCustom

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

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.

func (GateCustom) CoefValue

func (g GateCustom) CoefValue() *big.Int

Coefficient value of customized gate

func (GateCustom) InWires

func (g GateCustom) InWires() []uint64

Input wires of customized gate

func (GateCustom) OutWire

func (g GateCustom) OutWire() uint64

Output wires of customized gate

type GateMul

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

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.

func (GateMul) CoefValue

func (g GateMul) CoefValue() *big.Int

Coef of mul gate

func (GateMul) InWires

func (g GateMul) InWires() []uint64

Input wires of mul gate

func (GateMul) OutWire

func (g GateMul) OutWire() uint64

Output wire of mul gate

type RootCircuit

type RootCircuit struct {
	NumPublicInputs         int
	NumActualOutputs        int
	ExpectedNumOutputZeroes int
	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 (*RootCircuit) Graphviz

func (rc *RootCircuit) Graphviz() string

generate graphviz compatible DOT file for visualizing the circuit layout

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