v0.7.0 Latest Latest

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

Go to latest
Published: Mar 25, 2022 License: Apache-2.0 Imports: 12 Imported by: 0




View Source
const (
	CoeffIdZero     = 0
	CoeffIdOne      = 1
	CoeffIdTwo      = 2
	CoeffIdMinusOne = 3

ids of the coefficients with simple values in any cs.coeffs slice.


This section is empty.


This section is empty.


type ConstraintSystem

type ConstraintSystem struct {

	// schema of the circuit
	Schema *schema.Schema

	// number of wires
	NbInternalVariables int
	NbPublicVariables   int
	NbSecretVariables   int

	// input wires names
	Public, Secret []string

	// logs (added with cs.Println, resolved when solver sets a value to a wire)
	Logs []LogEntry

	// debug info contains stack trace (including line number) of a call to a cs.API that
	// results in an unsolved constraint
	DebugInfo []LogEntry

	// maps constraint id to debugInfo id
	// several constraints may point to the same debug info
	MDebug map[int]int

	Counters []Counter // TODO @gbotrel no point in serializing these

	MHints             map[int]*Hint      // maps wireID to hint
	MHintsDependencies map[hint.ID]string // maps hintID to hint string identifier

	// each level contains independent constraints and can be parallelized
	// it is guaranteed that all dependncies for constraints in a level l are solved
	// in previous levels
	Levels [][]int

	CurveID ecc.ID

ConstraintSystem contains common element between R1CS and ConstraintSystem

func (*ConstraintSystem) AddDebugInfo

func (cs *ConstraintSystem) AddDebugInfo(errName string, i ...interface{}) int

func (*ConstraintSystem) BitLen

func (cs *ConstraintSystem) BitLen() int

bitLen returns the number of bits needed to represent a fr.Element

func (*ConstraintSystem) Curve

func (cs *ConstraintSystem) Curve() ecc.ID

func (*ConstraintSystem) GetCounters

func (cs *ConstraintSystem) GetCounters() []Counter

GetCounters return the collected constraint counters, if any

func (*ConstraintSystem) GetNbVariables

func (cs *ConstraintSystem) GetNbVariables() (internal, secret, public int)

GetNbVariables return number of internal, secret and public variables

func (*ConstraintSystem) GetSchema

func (cs *ConstraintSystem) GetSchema() *schema.Schema

type Counter

type Counter struct {
	From, To      string
	NbVariables   int
	NbConstraints int
	CurveID       ecc.ID
	BackendID     backend.ID

Counter contains measurements of useful statistics between two Tag

func (Counter) String

func (c Counter) String() string

type Hint

type Hint struct {
	ID     hint.ID       // hint function id
	Inputs []interface{} // terms to inject in the hint function
	Wires  []int         // IDs of wires the hint outputs map to

Hint represents a solver hint it enables the solver to compute a Wire with a function provided at solving time using pre-defined inputs

func (Hint) MarshalCBOR

func (h Hint) MarshalCBOR() ([]byte, error)

func (*Hint) UnmarshalCBOR

func (h *Hint) UnmarshalCBOR(b []byte) error

type LinearExpression

type LinearExpression []Term

A linear expression is a linear combination of Term

func (LinearExpression) Clone

Clone returns a copy of the underlying slice

func (LinearExpression) Equal

Equals returns true if both SORTED expressions are the same

pre conditions: l and o are sorted

func (LinearExpression) HashCode

func (l LinearExpression) HashCode() uint64

HashCode returns a fast-to-compute but NOT collision resistant hash code identifier for the linear expression

func (LinearExpression) Len

func (l LinearExpression) Len() int

Len return the lenght of the Variable (implements Sort interface)

func (LinearExpression) Less

func (l LinearExpression) Less(i, j int) bool

Less returns true if variableID for term at i is less than variableID for term at j (implements Sort interface)

func (LinearExpression) Swap

func (l LinearExpression) Swap(i, j int)

Swap swaps terms in the Variable (implements Sort interface)

type LogEntry

type LogEntry struct {
	Caller    string
	Format    string
	ToResolve []Term

LogEntry is used as a shared data structure between the frontend and the backend to represent string values (in logs or debug info) where a value is not known at compile time (which is the case for variables that need to be resolved in the R1CS)

func (*LogEntry) WriteTerm

func (l *LogEntry) WriteTerm(t Term, sbb *strings.Builder)

func (*LogEntry) WriteVariable

func (l *LogEntry) WriteVariable(le LinearExpression, sbb *strings.Builder)

type R1C

type R1C struct {
	L, R, O LinearExpression

R1C used to compute the wires

func (*R1C) String

func (r1c *R1C) String(coeffs []big.Int) string

type R1CS

type R1CS struct {
	Constraints []R1C

R1CS decsribes a set of R1C constraint

func (*R1CS) GetNbConstraints

func (r1cs *R1CS) GetNbConstraints() int

GetNbConstraints returns the number of constraints

type SparseR1C

type SparseR1C struct {
	L, R, O Term
	M       [2]Term
	K       int // stores only the ID of the constant term that is used

SparseR1C used to compute the wires L+R+M[0]M[1]+O+k=0 if a Term is zero, it means the field doesn't exist (ex M=[0,0] means there is no multiplicative term)

func (*SparseR1C) String

func (r1c *SparseR1C) String(coeffs []big.Int) string

type SparseR1CS

type SparseR1CS struct {
	Constraints []SparseR1C

R1CS decsribes a set of SparseR1C constraint

func (*SparseR1CS) GetNbConstraints

func (cs *SparseR1CS) GetNbConstraints() int

GetNbConstraints returns the number of constraints

type Term

type Term uint64

Term lightweight version of a term, no pointers. A term packs wireID, coeffID, visibility and some metadata associated with the term, in a uint64. note: if we support more than 1 billion constraints, this breaks (not so soon.)

const TermDelimitor Term = Term(maskDelimitor)

TermDelimitor is reserved for internal use the constraint solver will evaluate the sum of all terms appearing between two TermDelimitor

func Pack

func Pack(variableID, coeffID int, variableVisiblity schema.Visibility) Term

Pack packs variableID, coeffID and coeffValue into Term first 5 bits are reserved to encode visibility of the constraint and coeffValue of the coefficient next 30 bits represented the coefficient idx (in r1cs.Coefficients) by which the wire is multiplied next 29 bits represent the constraint used to compute the wire if we support more than 500 millions constraints, this breaks (not so soon.)

func (Term) CoeffID

func (t Term) CoeffID() int

CoeffID returns the coefficient id (see R1CS data structure)

func (*Term) SetCoeffID

func (t *Term) SetCoeffID(cID int)

SetCoeffID update the bits correponding to the coeffID with cID

func (*Term) SetVariableVisibility

func (t *Term) SetVariableVisibility(v schema.Visibility)

SetVariableVisibility update the bits correponding to the variableVisiblity with its encoding

func (*Term) SetWireID

func (t *Term) SetWireID(cID int)

SetWireID update the bits correponding to the variableID with cID

func (Term) Unpack

func (t Term) Unpack() (coeffID, variableID int, variableVisiblity schema.Visibility)

Unpack returns coeffID, variableID and visibility

func (Term) VariableVisibility

func (t Term) VariableVisibility() schema.Visibility

VariableVisibility returns encoded schema.Visibility attribute

func (Term) WireID

func (t Term) WireID() int

WireID returns the variableID (see R1CS data structure)

Jump to

Keyboard shortcuts

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