Documentation
¶
Overview ¶
package frontend contains Constraint System representation and R1CS to be used with zero knowledge proof systems in gnark
Index ¶
- Variables
- type Assert
- type CS
- func (cs *CS) ADD(i1, i2 interface{}, in ...interface{}) *Constraint
- func (cs *CS) ALLOCATE(input interface{}) *Constraint
- func (cs *CS) DIV(i1, i2 interface{}) *Constraint
- func (cs *CS) FROM_BINARY(b ...*Constraint) *Constraint
- func (cs *CS) INV(c1 *Constraint) *Constraint
- func (cs *CS) MUL(i1, i2 interface{}, in ...interface{}) *Constraint
- func (cs *CS) MUSTBE_BOOLEAN(c *Constraint)
- func (cs *CS) MUSTBE_EQ(i1, i2 interface{})
- func (cs *CS) MUSTBE_LESS_OR_EQ(c *Constraint, bound interface{}, nbBits int)
- func (cs *CS) PUBLIC_INPUT(name string) *Constraint
- func (cs *CS) SECRET_INPUT(name string) *Constraint
- func (cs *CS) SELECT(b *Constraint, i1, i2 interface{}) *Constraint
- func (cs *CS) SELECT_LUT(c1, c0 *Constraint, lookuptable [4]big.Int) *Constraint
- func (cs *CS) SUB(i1, i2 interface{}) *Constraint
- func (cs *CS) String() string
- func (cs *CS) TO_BINARY(c *Constraint, nbBits int) []*Constraint
- func (circuit *CS) ToR1CS() *R1CS
- func (cs *CS) XOR(c1, c2 *Constraint) *Constraint
- type Constraint
- type LinearCombination
- type LinearExpression
- type R1C
- type R1CS
- type SolvingMethod
- type Term
- type TermR1cs
Constants ¶
This section is empty.
Variables ¶
var (
ErrInconsistantConstraint = errors.New("inconsistant constraint")
)
Functions ¶
This section is empty.
Types ¶
type Assert ¶
type Assert struct {
*require.Assertions
// contains filtered or unexported fields
}
Assert is a helper to test circuits
type CS ¶
type CS struct {
// under the key i are all the expressions that must be equal to a single wire
Constraints map[uint64]*Constraint
// constraints yielding multiple outputs (eg unpacking)
MOConstraints []moExpression
// constraints yielding no outputs (eg boolean constraints)
NOConstraints []expression
// contains filtered or unexported fields
}
CS Constraint System
func (*CS) ADD ¶
func (cs *CS) ADD(i1, i2 interface{}, in ...interface{}) *Constraint
ADD Adds 2+ inputs and returns resulting Constraint
func (*CS) ALLOCATE ¶
func (cs *CS) ALLOCATE(input interface{}) *Constraint
ALLOCATE will return an allocated cs.Constraint from input {Constraint, element, uint64, int, ...}
func (*CS) DIV ¶
func (cs *CS) DIV(i1, i2 interface{}) *Constraint
DIV divides two constraints (i1/i2)
func (*CS) FROM_BINARY ¶
func (cs *CS) FROM_BINARY(b ...*Constraint) *Constraint
FROM_BINARY packs b, seen as a fr.Element in little endian
func (*CS) MUL ¶
func (cs *CS) MUL(i1, i2 interface{}, in ...interface{}) *Constraint
MUL Multiplies 2+ constraints together
func (*CS) MUSTBE_BOOLEAN ¶
func (cs *CS) MUSTBE_BOOLEAN(c *Constraint)
MUSTBE_BOOLEAN boolean constrains a variable
func (*CS) MUSTBE_EQ ¶
func (cs *CS) MUSTBE_EQ(i1, i2 interface{})
MUSTBE_EQ equalizes two constraints
func (*CS) MUSTBE_LESS_OR_EQ ¶
func (cs *CS) MUSTBE_LESS_OR_EQ(c *Constraint, bound interface{}, nbBits int)
MUSTBE_LESS_OR_EQ constrains c to be less or equal than e (taken as lifted Integer values from Fr) from https://github.com/zcash/zips/blob/master/protocol/protocol.pdf
func (*CS) PUBLIC_INPUT ¶
func (cs *CS) PUBLIC_INPUT(name string) *Constraint
PUBLIC_INPUT creates a Constraint containing an input
func (*CS) SECRET_INPUT ¶
func (cs *CS) SECRET_INPUT(name string) *Constraint
SECRET_INPUT creates a Constraint containing an input
func (*CS) SELECT ¶
func (cs *CS) SELECT(b *Constraint, i1, i2 interface{}) *Constraint
SELECT if b is true, yields c1 else yields c2
func (*CS) SELECT_LUT ¶
func (cs *CS) SELECT_LUT(c1, c0 *Constraint, lookuptable [4]big.Int) *Constraint
SELECT_LUT select lookuptable[c1*2+c0] where c0 and c1 are boolean constrained cf https://z.cash/technology/jubjub/
func (*CS) TO_BINARY ¶
func (cs *CS) TO_BINARY(c *Constraint, nbBits int) []*Constraint
TO_BINARY unpacks a variable in binary, n is the number of bits of the variable The result in in little endian (first bit= lsb)
func (*CS) XOR ¶
func (cs *CS) XOR(c1, c2 *Constraint) *Constraint
XOR compute the xor between two constraints
type Constraint ¶
type Constraint struct {
// contains filtered or unexported fields
}
Constraint list of expressions that must be equal+an output wire, that can be computed out of the inputs wire. A Constraint is a list of expressions that are equal. Each expression yields the value of another wire. A Constraint contains only one wire expression, and at least one expression, unless the wire expression is an input. under the constraintID i are all the expressions that must be equal under the constraintID i, exactly one Constraint can be single wire and there is at least a linear Constraint or a single wire
func (*Constraint) Tag ¶
func (c *Constraint) Tag(tag string)
Tag adds a tag to the constraint's singleWire once the R1CS system is solved r1cs.Inspect() may return a map[string]value of constraints with Tags
type LinearCombination ¶
type LinearCombination []Term
LinearCombination linear combination of constraints
type R1C ¶
type R1C struct {
L LinearExpression
R LinearExpression
O LinearExpression
Solver SolvingMethod
}
R1C used to compute the wires
type R1CS ¶
type R1CS struct {
// Wires
NbWires int
NbPublicWires int // includes ONE wire
NbPrivateWires int
PrivateWires []string // private wire names
PublicWires []string // public wire names
WireTags map[int][]string // optional tags -- debug info
// Constraints
NbConstraints int // total number of constraints
NbCOConstraints int // number of constraints that need to be solved, the first of the Constraints slice
Constraints []R1C
}
R1CS decsribes a set of R1CS constraint
type SolvingMethod ¶
type SolvingMethod uint8
method to solve a r1cs
const ( SingleOutput SolvingMethod = iota BinaryDec )