Documentation ¶
Overview ¶
Package cs contains Constraint System representation and R1CS to be used with zero knowledge proof systems in gnark
Index ¶
- Constants
- Variables
- func Element(i1 interface{}) curve.Element
- type Assert
- type Assignment
- type Assignments
- 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, input interface{})
- 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]curve.Element) *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 (cs *CS) Write(path string)
- func (cs *CS) XOR(c1, c2 *Constraint) *Constraint
- type Constraint
- type LinearCombination
- type R1CS
- func (r1cs R1CS) Inspect() (map[string]curve.Element, error)
- func (r1cs *R1CS) NbConstraints() int
- func (r1cs *R1CS) NbPrivateInputs() int
- func (r1cs *R1CS) NbPublicInputs() int
- func (r1cs *R1CS) Solve(assignment map[string]Assignment) (a, b, c []curve.Element, err error)
- func (r1cs R1CS) String() string
- type Term
- type Visibility
Constants ¶
const CurveID = curve.CurveID
CurveID exposes the CurveID cs package is being compiled with (see internal/curve)
const OneWire = "ONE_WIRE"
OneWire is the assignment label / name used for the constant wire one
Variables ¶
var ( ErrDuplicateTag = errors.New("duplicate tag") ErrInconsistantConstraint = errors.New("inconsistant constraint") ErrInputNotSet = errors.New("input not set") ErrInputVisiblity = errors.New("input has incorrect visibility (secret / public)") ErrUnsatisfiedConstraint = errors.New("constraint is not satisfied") )
Functions ¶
Types ¶
type Assert ¶
type Assert struct { *require.Assertions // contains filtered or unexported fields }
Assert is a helper to test circuits
func NewAssert ¶
NewAssert returns an helper to test Constraint Systems this helper embeds a stretch/testify Assert object for convenience
func (*Assert) NotSolved ¶
func (assert *Assert) NotSolved(circuit CS, solution Assignments)
NotSolved check that a solution does NOT solve a circuit error may be missing inputs or unsatisfied constraints
func (*Assert) Solved ¶
func (assert *Assert) Solved(circuit CS, solution Assignments, expectedValues map[string]interface{})
Solved check that a solution solves a circuit for each expectedValues, this helper compares the output from r1cs.Inspect() after Solving. this helper also ensure the result vectors a*b=c
type Assignment ¶
type Assignment struct { Value curve.Element IsPublic bool // default == false (assignemnt is private) }
Assignment is used to specify inputs to the Prove and Verify functions
type Assignments ¶
type Assignments map[string]Assignment
Assignments is used to specify inputs to the Prove and Verify functions
func NewAssignment ¶
func NewAssignment() Assignments
NewAssignment returns an empty Assigments object
func (Assignments) Assign ¶
func (a Assignments) Assign(visibility Visibility, name string, v interface{})
Assign assign a value to a Secret/Public input identified by its name
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 c = bi*2^i (first item of b = LSb of c)
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, input interface{})
MUSTBE_LESS_OR_EQ constrains c to be less or equal than e (taken as lifted Integer values from Fr)
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]curve.Element) *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 R1CS ¶
type R1CS struct { //wiretracker = [..PrivateInputsStartIndex-1] || [PrivateInputsStartIndex..PublicInputsStartIndex-1] || [PublicInputsStartIndex...]. The label of the wire is the index in the wire tracker PrivateInputsStartIndex int PublicInputsStartIndex int // index i = wire with index i WireTracker []wire // Actual description of the constraint system GraphOrdering []int64 // order in which to compute the computational graph ComputationalGraph []r1c // Constraints to instantiate the variables Constraints []r1c // Constraints left from the computational graph }
R1CS decsribes a set of R1CS constraint
func (*R1CS) NbConstraints ¶
NbConstraints returns the number of Constraints
func (*R1CS) NbPrivateInputs ¶
NbPrivateInputs returns the number of Private inputs
func (*R1CS) NbPublicInputs ¶
NbPublicInputs returns the number of Public inputs (without the ONEWIRE)
type Visibility ¶
type Visibility string
Visibility type alias on string to define circuit input's visibility
const ( Secret Visibility = "secret" Public Visibility = "public" )
Possible Visibility attributes for circuit inputs
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
encoding
|
|
Package groth16 exposes zkSNARK (Groth16) 3 algorithms: Setup, Prove and Verify
|
Package groth16 exposes zkSNARK (Groth16) 3 algorithms: Setup, Prove and Verify |
internal
|
|
curve
Package curve enables the cs package to use various curves through build tags
|
Package curve enables the cs package to use various curves through build tags |
Package std contains 2 sub-tree: reference and gadget reference is completly independant from gadget gadget may use reference data-structures not all gadget need a reference implementation, but that's helpful, at least for testing purposes
|
Package std contains 2 sub-tree: reference and gadget reference is completly independant from gadget gadget may use reference data-structures not all gadget need a reference implementation, but that's helpful, at least for testing purposes |