compiled

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LinearExpression

type LinearExpression []Term

LinearExpression represent a linear expression of variables

func (LinearExpression) Clone

Clone returns a copy of the underlying slice

type LogEntry

type LogEntry struct {
	Format    string
	ToResolve []int
}

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)

type R1C

R1C used to compute the wires

type R1CS

type R1CS struct {
	// Wires
	NbInternalVariables int
	NbPublicVariables   int // includes ONE wire
	NbSecretVariables   int
	Logs                []LogEntry
	DebugInfo           []LogEntry

	// 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 The coefficients from the rank-1 constraint it contains are big.Int and not tied to a curve base field

func (*R1CS) CurveID

func (r1cs *R1CS) CurveID() ecc.ID

CurveID returns ecc.UNKNOWN as this is a untyped R1CS using big.Int

func (*R1CS) FrSize

func (r1cs *R1CS) FrSize() int

FrSize panics

func (*R1CS) GetNbCoefficients

func (r1cs *R1CS) GetNbCoefficients() int

GetNbCoefficients return the number of unique coefficients needed in the R1CS

func (*R1CS) GetNbConstraints

func (r1cs *R1CS) GetNbConstraints() int

GetNbConstraints returns the number of constraints

func (*R1CS) GetNbVariables

func (r1cs *R1CS) GetNbVariables() (internal, secret, public int)

GetNbVariables return number of internal, secret and public variables

func (*R1CS) ReadFrom

func (r1cs *R1CS) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom panics (can't deserialize untyped R1CS)

func (*R1CS) SetLoggerOutput

func (r1cs *R1CS) SetLoggerOutput(w io.Writer)

SetLoggerOutput replace existing logger output with provided one default uses os.Stdout if nil is provided, logs are not printed

func (*R1CS) WriteTo

func (r1cs *R1CS) WriteTo(w io.Writer) (n int64, err error)

WriteTo panics (can't serialize untyped R1CS)

type SolvingMethod

type SolvingMethod uint8

SolvingMethod is used by the R1CS solver note: it is not in backend/r1cs to avoid an import cycle

const (
	SingleOutput SolvingMethod = iota
	BinaryDec
)

SingleOuput and BinaryDec are types of solving method for rank-1 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
	Solver  SolvingMethod
}

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)

type SparseR1CS

type SparseR1CS struct {

	// Variables [ publicVariables|  secretVariables | internalVariables ]
	NbInternalVariables int
	NbPublicVariables   int
	NbSecretVariables   int

	// Constraints
	Constraints []SparseR1C // list of PLONK constraints that yield an output (for example v3 == v1 * v2, return v3)
	Assertions  []SparseR1C // list of PLONK constraints that yield no output (for example ensuring v1 == v2)

	// Logs (e.g. variables that have been printed using cs.Println)
	Logs []LogEntry

	// Coefficients in the constraints
	Coeffs    []big.Int      // list of unique coefficients.
	CoeffsIDs map[string]int // map to fast check existence of a coefficient (key = coeff.Text(16))
}

SparseR1CS represents a Plonk like circuit

func (*SparseR1CS) CurveID

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

CurveID returns ecc.UNKNOWN as this is a untyped R1CS using big.Int

func (*SparseR1CS) FrSize

func (cs *SparseR1CS) FrSize() int

FrSize panics

func (*SparseR1CS) GetNbCoefficients

func (cs *SparseR1CS) GetNbCoefficients() int

GetNbCoefficients return the number of unique coefficients needed in the R1CS

func (*SparseR1CS) GetNbConstraints

func (cs *SparseR1CS) GetNbConstraints() int

GetNbConstraints returns the number of constraints

func (*SparseR1CS) GetNbVariables

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

GetNbVariables return number of internal, secret and public variables

func (*SparseR1CS) GetNbWires

func (cs *SparseR1CS) GetNbWires() int

GetNbWires returns the number of wires (internal)

func (*SparseR1CS) ReadFrom

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

ReadFrom panics

func (*SparseR1CS) SetLoggerOutput

func (cs *SparseR1CS) SetLoggerOutput(w io.Writer)

SetLoggerOutput replace existing logger output with provided one default uses os.Stdout if nil is provided, logs are not printed

func (*SparseR1CS) WriteTo

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

WriteTo panics

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.)

func Pack

func Pack(variableID, coeffID int, variableVisiblity Visibility, coeffValue ...int) 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) CoeffValue

func (t Term) CoeffValue() int

CoeffValue return maxInt if no special value is set if set, returns either -1, 0, 1 or 2

func (*Term) SetCoeffID

func (t *Term) SetCoeffID(cID int)

SetCoeffID update the bits correponding to the coeffID with cID

func (*Term) SetCoeffValue

func (t *Term) SetCoeffValue(val int)

SetCoeffValue update the bits correponding to the coeffValue with its encoding

func (*Term) SetVariableID

func (t *Term) SetVariableID(cID int)

SetVariableID update the bits correponding to the variableID with cID

func (*Term) SetVariableVisibility

func (t *Term) SetVariableVisibility(v Visibility)

SetVariableVisibility update the bits correponding to the variableVisiblity with its encoding

func (Term) Unpack

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

Unpack returns coeffValue, coeffID and variableID

func (Term) VariableID

func (t Term) VariableID() int

VariableID returns the variableID (see R1CS data structure)

func (Term) VariableVisibility

func (t Term) VariableVisibility() Visibility

VariableVisibility returns encoded Visibility attribute

type Visibility

type Visibility uint8

Visibility encodes a Variable (or wire) visibility Possible values are Unset, Internal, Secret or Public

const (
	Unset Visibility = iota
	Internal
	Secret
	Public
)

Jump to

Keyboard shortcuts

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