compiled

package
v0.6.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

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

View Source
const R1CSTemplate = `` /* 1953-byte string literal not displayed */
View Source
const SparseR1CSTemplate = `` /* 2288-byte string literal not displayed */

Variables

This section is empty.

Functions

This section is empty.

Types

type CS added in v0.5.1

type CS struct {

	// number of wires
	NbInternalVariables int
	NbPublicVariables   int
	NbSecretVariables   int

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

	// a wire may point to at most one hint
	MHints map[int]*Hint

	Schema *schema.Schema

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

CS contains common element between R1CS and CS

func (*CS) CurveID added in v0.5.1

func (cs *CS) CurveID() ecc.ID

CurveID returns ecc.UNKNOWN

func (*CS) FrSize added in v0.5.1

func (cs *CS) FrSize() int

FrSize panics

func (*CS) GetConstraints added in v0.6.1

func (cs *CS) GetConstraints() [][]string

func (*CS) GetCounters added in v0.6.0

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

GetCounters return the collected constraint counters, if any

func (*CS) GetNbCoefficients added in v0.5.1

func (cs *CS) GetNbCoefficients() int

GetNbCoefficients panics

func (*CS) GetNbVariables added in v0.5.1

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

GetNbVariables return number of internal, secret and public variables

func (*CS) GetSchema added in v0.6.1

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

func (*CS) ReadFrom added in v0.5.1

func (cs *CS) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom panics

func (*CS) ToHTML added in v0.5.1

func (cs *CS) ToHTML(w io.Writer) error

ToHTML panics

func (*CS) WriteTo added in v0.5.1

func (cs *CS) WriteTo(w io.Writer) (n int64, err error)

WriteTo panics

type Counter added in v0.6.0

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 added in v0.6.0

func (c Counter) String() string

type Hint added in v0.5.1

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 added in v0.6.0

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

func (*Hint) UnmarshalCBOR added in v0.6.0

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

type LinearExpression

type LinearExpression []Term

func (LinearExpression) Equal added in v0.5.2

Equals returns true if both SORTED expressions are the same

pre conditions: l and o are sorted

func (LinearExpression) Len added in v0.5.0

func (v LinearExpression) Len() int

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

func (LinearExpression) Less added in v0.5.0

func (v 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 added in v0.5.0

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

Swap swaps terms in the Variable (implements Sort interface)

type LogEntry

type LogEntry struct {
	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 added in v0.5.1

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

func (*LogEntry) WriteVariable added in v0.6.0

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

type R1C

type R1C struct {
	L, R, O Variable
}

R1C used to compute the wires

func (*R1C) String added in v0.5.1

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

type R1CS

type R1CS struct {
	CS
	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 added in v0.5.1

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

type SparseR1CS

type SparseR1CS struct {
	CS
	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 first 4 bits are reserved next 30 bits represented the coefficient idx (in r1cs.Coefficients) by which the wire is multiplied next 30 bits represent the constraint used to compute the wire 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 added in v0.6.0

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 added in v0.6.0

func (t Term) WireID() int

WireID returns the variableID (see R1CS data structure)

type Variable added in v0.6.0

type Variable struct {
	LinExp    LinearExpression
	IsBoolean *bool
}

Variable represent a linear expression of wires

func (Variable) AssertIsSet added in v0.6.0

func (v Variable) AssertIsSet()

assertIsSet panics if the variable is unset this may happen if inside a Define we have var a variable cs.Mul(a, 1) since a was not in the circuit struct it is not a secret variable

func (Variable) Clone added in v0.6.0

func (v Variable) Clone() Variable

Clone returns a copy of the underlying slice

func (*Variable) IsConstant added in v0.6.0

func (v *Variable) IsConstant() bool

isConstant returns true if the variable is ONE_WIRE * coeff

Jump to

Keyboard shortcuts

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