cs

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: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsatisfiedConstraint = errors.New("constraint is not satisfied")

ErrUnsatisfiedConstraint can be generated when solving a R1CS

Functions

This section is empty.

Types

type R1CS

type R1CS struct {
	compiled.R1CS
	Coefficients []fr.Element // R1C coefficients indexes point here
	// contains filtered or unexported fields
}

R1CS decsribes a set of R1CS constraint

func NewR1CS

func NewR1CS(r1cs compiled.R1CS, coefficients []big.Int) *R1CS

NewR1CS returns a new R1CS and sets r1cs.Coefficient (fr.Element) from provided big.Int values

func (*R1CS) AddTerm

func (r1cs *R1CS) AddTerm(res *fr.Element, t compiled.Term, value fr.Element) *fr.Element

AddTerm returns res += (value * term.Coefficient)

func (*R1CS) CurveID

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

CurveID returns curve ID as defined in gnark-crypto (ecc.BLS12-381)

func (*R1CS) FrSize

func (r1cs *R1CS) FrSize() int

FrSize return fr.Limbs * 8, size in byte of a fr element

func (*R1CS) GetNbCoefficients

func (r1cs *R1CS) GetNbCoefficients() int

GetNbCoefficients return the number of unique coefficients needed in the R1CS

func (*R1CS) IsSolved

func (r1cs *R1CS) IsSolved(witness []fr.Element) error

IsSolved returns nil if given witness solves the R1CS and error otherwise this method wraps r1cs.Solve() and allocates r1cs.Solve() inputs

func (*R1CS) ReadFrom

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

ReadFrom attempts to decode R1CS from io.Reader using cbor

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

func (r1cs *R1CS) Solve(witness []fr.Element, a, b, c, wireValues []fr.Element) error

Solve sets all the wires and returns the a, b, c vectors. the r1cs system should have been compiled before. The entries in a, b, c are in Montgomery form. witness: contains the input variables a, b, c vectors: ab-c = hz wireValues = [publicWires | secretWires | internalWires ] witness = [publicWires | secretWires] (without the ONE_WIRE !)

func (*R1CS) WriteTo

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

WriteTo encodes R1CS into provided io.Writer using cbor

type SparseR1CS

type SparseR1CS struct {
	compiled.SparseR1CS

	// Coefficients in the constraints
	Coefficients []fr.Element // list of unique coefficients.
}

SparseR1CS represents a Plonk like circuit

func NewSparseR1CS

func NewSparseR1CS(r1cs compiled.SparseR1CS, coefficients []big.Int) *SparseR1CS

NewSparseR1CS returns a new SparseR1CS and sets r1cs.Coefficient (fr.Element) from provided big.Int values

func (*SparseR1CS) CurveID

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

CurveID returns curve ID as defined in gnark-crypto (ecc.BLS12-381)

func (*SparseR1CS) FrSize

func (cs *SparseR1CS) FrSize() int

FrSize return fr.Limbs * 8, size in byte of a fr element

func (*SparseR1CS) GetNbCoefficients

func (cs *SparseR1CS) GetNbCoefficients() int

GetNbCoefficients return the number of unique coefficients needed in the R1CS

func (*SparseR1CS) IsSolved

func (cs *SparseR1CS) IsSolved(witness []fr.Element) error

IsSolved returns nil if given witness solves the R1CS and error otherwise this method wraps r1cs.Solve() and allocates r1cs.Solve() inputs

func (*SparseR1CS) Solve

func (cs *SparseR1CS) Solve(witness []fr.Element) (solution []fr.Element, err error)

Solve sets all the wires. wireValues = [publicInputs | secretInputs | internalVariables ] witness: contains the input variables it returns the full slice of wires

Jump to

Keyboard shortcuts

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