circuit

package
v0.0.0-...-89ef835 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: ISC Imports: 4 Imported by: 2

Documentation

Overview

Package circuit implements arithmetic circuits.

Index

Constants

View Source
const (
	Gate_Input    = iota
	Gate_Add      = iota
	Gate_AddConst = iota
	Gate_Mul      = iota
	Gate_MulConst = iota
)

Supported gate types.

Variables

View Source
var NegOne *big.Int

Global constant set to -1 in the field.

Functions

This section is empty.

Types

type Circuit

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

Circuit represents an arithmetic circuit over a particular finite field (specified by the modulus mod). The gates listed in shouldBeZero should all zero on their output wires iff the circuit accepts an input.

func AndCircuits

func AndCircuits(ckts []*Circuit) *Circuit

func CheckMul

func CheckMul(left, right, prod *Gate) *Circuit

A circuit that checks that

(left * right == output)

func Empty

func Empty() *Circuit

func NBits

func NBits(bits int, name string) *Circuit

A circuit that takes N inputs x1, ..., xN, which should all be 0/1 values in F.

The circuit first computes y_i = (x_i)*(x_i - 1) and requires that all y_i's are zero.

The output of the circuit is the sum:

\sum_i (2^i * x_i)

func OneBit

func OneBit(name string) *Circuit

A circuit that takes a single input x and computes

x*(x-1).

If x represents a 0/1 value in F, then this circuit outputs zero.

func UncheckedInput

func UncheckedInput(name string) *Circuit

Input -> Output circuit

func (*Circuit) AddGate

func (c *Circuit) AddGate(g *Gate)

func (*Circuit) AddZeroGate

func (c *Circuit) AddZeroGate(g *Gate)

func (*Circuit) Eval

func (c *Circuit) Eval(inputs []*big.Int) bool

Evaluate a circuit on the given input values. Return true iff the circuit accepts the input.

func (*Circuit) ImportWires

func (c *Circuit) ImportWires(prg *share.ReplayPRG)

Import shared wire values from a ReplayPRG.

func (*Circuit) InputGates

func (c *Circuit) InputGates() []*Gate

func (*Circuit) Modulus

func (c *Circuit) Modulus() *big.Int

func (*Circuit) MulGates

func (c *Circuit) MulGates() []*Gate

func (*Circuit) OutputName

func (c *Circuit) OutputName(i int) string

func (*Circuit) OutputNames

func (c *Circuit) OutputNames() []string

func (*Circuit) Outputs

func (c *Circuit) Outputs() []*Gate

func (*Circuit) ShareWires

func (c *Circuit) ShareWires(prg *share.GenPRG)

Split the wire values into shares.

func (*Circuit) ShouldBeZero

func (c *Circuit) ShouldBeZero() []*Gate

type Gate

type Gate struct {
	GateType int
	ParentL  *Gate
	ParentR  *Gate

	Constant *big.Int

	WireValue *big.Int
}

Gate represents a gate in an arithmetic circuit, and possibly holds the value on its output wire.

On inputs x and y, each bilinear gate computes output z, where

z = (A x + B)(A' y + B').

If both parents are nil, it's an input gate.

func MulByNegOne

func MulByNegOne(parent *Gate) *Gate

func NewGate

func NewGate() *Gate

func NewGates

func NewGates(n int) []*Gate

Jump to

Keyboard shortcuts

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