Documentation
¶
Index ¶
- Constants
- func FromInterface(input interface{}) big.Int
- type Blueprint
- type BlueprintGenericHint
- type BlueprintGenericR1C
- type BlueprintHint
- type BlueprintID
- type BlueprintR1C
- type BlueprintSolvable
- type CoeffTable
- type Commitment
- func (i *Commitment) Is() bool
- func (i *Commitment) NbCommitted() int
- func (i *Commitment) NbPublicCommitted() int
- func (i *Commitment) PrivateCommitted() []int
- func (i *Commitment) PrivateToPublic() []int
- func (i *Commitment) SerializeCommitment(privateCommitment []byte, publicCommitted []*big.Int, fieldByteLen int) []byte
- type Element
- type Field
- type HintMapping
- type Instruction
- type LinearExpression
- type R1C
- type R1CS
- type R1CSSolution
- type ReaderCounter
- type Resolver
- type Solver
- type StringBuilder
- type System
- func (system *System) AddBlueprint(b Blueprint) BlueprintID
- func (system *System) AddCommitment(c Commitment) error
- func (system *System) AddInternalVariable() (idx int)
- func (system *System) AddPublicVariable(name string) (idx int)
- func (system *System) AddSecretVariable(name string) (idx int)
- func (system *System) CheckSerializationHeader() error
- func (cs *System) CheckUnconstrainedWires() error
- func (system *System) Field() *big.Int
- func (system *System) FieldBitLen() int
- func (cs *System) GetCallData(instruction Instruction) []uint32
- func (system *System) GetInstruction(id int) Instruction
- func (cs *System) GetNbConstraints() int
- func (system *System) GetNbInstructions() int
- func (system *System) GetNbInternalVariables() int
- func (system *System) GetNbPublicVariables() int
- func (system *System) GetNbSecretVariables() int
- func (system *System) GetNbVariables() (internal, secret, public int)
- func (system *System) VariableToString(vID int) string
- type Term
- type UnsatisfiedConstraintError
- type WriterCounter
Constants ¶
const ( CoeffIdZero = iota CoeffIdOne CoeffIdTwo CoeffIdMinusOne CoeffIdMinusTwo )
ids of the coefficients with simple values in any cs.coeffs slice.
const CommitmentDst = "bsb22-commitment"
const ConstrainSystemTypeR1CS = 1
Variables ¶
This section is empty.
Functions ¶
func FromInterface ¶
FromInterface converts an interface to a big.Int element
input must be primitive (uintXX, intXX, []byte, string) or implement BigInt(res *big.Int) (which is the case for gnark-crypto field elements)
if the input is a string, it calls (big.Int).SetString(input, 0). In particular: The number prefix determines the actual base: A prefix of ”0b” or ”0B” selects base 2, ”0”, ”0o” or ”0O” selects base 8, and ”0x” or ”0X” selects base 16. Otherwise, the selected base is 10 and no prefix is accepted.
panics if the input is invalid
Types ¶
type Blueprint ¶
type Blueprint interface { // NbInputs return the number of calldata input this blueprint expects. // If this is unknown at compile time, implementation must return -1 and store // the actual number of inputs in the first index of the calldata. NbInputs() int // NbConstraints return the number of constraints this blueprint creates. NbConstraints() int }
Blueprint enable representing heterogenous constraints or instructions in a constraint system in a memory efficient way. Blueprints essentially help the frontend/ to "compress" constraints or instructions, and specify for the solving (or zksnark setup) part how to "decompress" and optionally "solve" the associated wires.
type BlueprintGenericHint ¶
type BlueprintGenericHint struct{}
func (*BlueprintGenericHint) CompressHint ¶
func (b *BlueprintGenericHint) CompressHint(h HintMapping) []uint32
func (*BlueprintGenericHint) DecompressHint ¶
func (b *BlueprintGenericHint) DecompressHint(h *HintMapping, calldata []uint32)
func (*BlueprintGenericHint) NbConstraints ¶
func (b *BlueprintGenericHint) NbConstraints() int
func (*BlueprintGenericHint) NbInputs ¶
func (b *BlueprintGenericHint) NbInputs() int
type BlueprintGenericR1C ¶
type BlueprintGenericR1C struct{}
BlueprintGenericR1C implements Blueprint and BlueprintR1C. Encodes
L * R == 0
func (*BlueprintGenericR1C) CompressR1C ¶
func (b *BlueprintGenericR1C) CompressR1C(c *R1C) []uint32
func (*BlueprintGenericR1C) DecompressR1C ¶
func (b *BlueprintGenericR1C) DecompressR1C(c *R1C, calldata []uint32)
func (*BlueprintGenericR1C) NbConstraints ¶
func (b *BlueprintGenericR1C) NbConstraints() int
func (*BlueprintGenericR1C) NbInputs ¶
func (b *BlueprintGenericR1C) NbInputs() int
type BlueprintHint ¶
type BlueprintHint interface { CompressHint(HintMapping) []uint32 DecompressHint(h *HintMapping, calldata []uint32) }
BlueprintHint indicates that the blueprint and associated calldata encodes a hint.
type BlueprintID ¶
type BlueprintID uint32
type BlueprintR1C ¶
type BlueprintR1C interface { CompressR1C(c *R1C) []uint32 DecompressR1C(into *R1C, calldata []uint32) }
BlueprintR1C indicates that the blueprint and associated calldata encodes a R1C
type BlueprintSolvable ¶
type BlueprintSolvable interface { // Solve may return an error if the decoded constraint / calldata is unsolvable. Solve(s Solver, calldata []uint32) error }
BlueprintSolvable represents a blueprint that knows how to solve itself.
type CoeffTable ¶
CoeffTable ensure we store unique coefficients in the constraint system
func (*CoeffTable) AddCoeff ¶
func (ct *CoeffTable) AddCoeff(coeff Element) uint32
func (*CoeffTable) CoeffToString ¶
func (ct *CoeffTable) CoeffToString(cID int) string
CoeffToString implements constraint.Resolver
type Commitment ¶
type Commitment struct { Committed []int // sorted list of id's of committed variables in groth16. in plonk, list of indexes of constraints defining committed values NbPrivateCommitted int HintID hintsolver.HintID // TODO @gbotrel we probably don't need that here CommitmentIndex int // in groth16, CommitmentIndex is the wire index. in plonk, it's the constraint defining it CommittedAndCommitment []int // sorted list of id's of committed variables AND the commitment itself }
func NewCommitment ¶
func NewCommitment(committed []int, nbPublicCommitted int) Commitment
NewCommitment initialize a Commitment object
- committed are the sorted wireID to commit to (without duplicate)
- nbPublicCommited is the number of public inputs among the commited wireIDs
func (*Commitment) Is ¶
func (i *Commitment) Is() bool
func (*Commitment) NbCommitted ¶
func (i *Commitment) NbCommitted() int
func (*Commitment) NbPublicCommitted ¶
func (i *Commitment) NbPublicCommitted() int
func (*Commitment) PrivateCommitted ¶
func (i *Commitment) PrivateCommitted() []int
func (*Commitment) PrivateToPublic ¶
func (i *Commitment) PrivateToPublic() []int
PrivateToPublic returns indexes of variables which are private to the constraint system, but public to Groth16. That is, private committed variables and the commitment itself
func (*Commitment) SerializeCommitment ¶
type Element ¶
type Element [6]uint64
Element represents a term coefficient data. It is instantiated by the concrete constraint system implementation. Most of the scalar field used in gnark are on 4 uint64, so we have a clear memory overhead here.
type Field ¶
type Field interface { FromInterface(interface{}) Element ToBigInt(Element) *big.Int Mul(a, b Element) Element Add(a, b Element) Element Sub(a, b Element) Element Neg(a Element) Element Inverse(a Element) (Element, bool) One() Element IsOne(Element) bool String(Element) string }
Field capability to perform arithmetic on Coeff
type HintMapping ¶
type HintMapping struct { HintID csolver.HintID // Hint function id Inputs []LinearExpression // Terms to inject in the hint function OutputRange struct { Start, End uint32 } }
HintMapping mark a list of output variables to be computed using provided hint and inputs.
func (*HintMapping) WireIterator ¶
func (h *HintMapping) WireIterator() func() int
WireIterator implements constraint.Iterable returns all the wires referenced by the hint.
type Instruction ¶
type Instruction struct { // BlueprintID maps this instruction to a blueprint BlueprintID BlueprintID // ConstraintOffset stores the starting constraint ID of this instruction. // Might not be strictly necessary; but speeds up solver for instructions that represents // multiple constraints. ConstraintOffset uint32 // The constraint system stores a single []uint32 calldata slice. StartCallData // points to the starting index in the mentioned slice. This avoid storing a slice per // instruction (3 * uint64 in memory). StartCallData uint64 }
Instruction is the lowest element of a constraint system. It stores just enough data to reconstruct a constraint of any shape or a hint at solving time.
type LinearExpression ¶
type LinearExpression []Term
A LinearExpression is a linear combination of Term
func (LinearExpression) Clone ¶
func (l LinearExpression) Clone() LinearExpression
Clone returns a copy of the underlying slice
func (LinearExpression) String ¶
func (l LinearExpression) String(r Resolver) string
type R1C ¶
type R1C struct {
L, R, O LinearExpression
}
R1C used to compute the wires
func (*R1C) WireIterator ¶
WireIterator implements constraint.Iterable
type R1CSSolution ¶
R1CSSolution represent a valid assignment to all the variables in the constraint system. The vector W such that Aw o Bw - Cw = 0
type ReaderCounter ¶
type Resolver ¶
type Resolver interface { CoeffToString(coeffID int) string VariableToString(variableID int) string }
Resolver allows pretty printing of constraints.
type Solver ¶
type Solver interface { Field GetValue(cID, vID uint32) Element GetCoeff(cID uint32) Element SetValue(vID uint32, f Element) IsSolved(vID uint32) bool }
Solver represents the state of a constraint system solver at runtime. Blueprint can interact with this object to perform run time logic, solve constraints and assign values in the solution.
type StringBuilder ¶
StringBuilder is a helper to build string from constraints, linear expressions or terms. It embeds a strings.Builder object for convenience.
func NewStringBuilder ¶
func NewStringBuilder(r Resolver) *StringBuilder
NewStringBuilder returns a new StringBuilder.
func (*StringBuilder) WriteLinearExpression ¶
func (sbb *StringBuilder) WriteLinearExpression(l LinearExpression)
WriteLinearExpression appends the linear expression to the current buffer
func (*StringBuilder) WriteTerm ¶
func (sbb *StringBuilder) WriteTerm(t Term)
WriteLinearExpression appends the term to the current buffer
type System ¶
type System struct { // serialization header ScalarField string Type int Instructions []Instruction Blueprints []Blueprint CallData []uint32 // huge slice. // can be != than len(instructions) NbConstraints int // number of internal wires NbInternalVariables int // input wires names Public, Secret []string // maps hintID to hint string identifier MHintsDependencies map[hintsolver.HintID]string // each level contains independent constraints and can be parallelized // it is guaranteed that all dependencies for constraints in a level l are solved // in previous levels // TODO @gbotrel these are currently updated after we add a constraint. // but in case the object is built from a serialized representation // we need to init the level builder lbWireLevel from the existing constraints. Levels [][]int CommitmentInfo Commitment // contains filtered or unexported fields }
System contains core elements for a constraint System
func (*System) AddBlueprint ¶
func (system *System) AddBlueprint(b Blueprint) BlueprintID
func (*System) AddCommitment ¶
func (system *System) AddCommitment(c Commitment) error
func (*System) AddInternalVariable ¶
func (*System) AddPublicVariable ¶
func (*System) AddSecretVariable ¶
func (*System) CheckSerializationHeader ¶
CheckSerializationHeader parses the scalar field and gnark version headers
This is meant to be use at the deserialization step, and will error for illegal values
func (*System) CheckUnconstrainedWires ¶
func (*System) FieldBitLen ¶
bitLen returns the number of bits needed to represent a fr.Element
func (*System) GetCallData ¶
func (cs *System) GetCallData(instruction Instruction) []uint32
GetCallData re-slice the constraint system full calldata slice with the portion related to the instruction. This does not copy and caller should not modify.
func (*System) GetInstruction ¶
func (system *System) GetInstruction(id int) Instruction
func (*System) GetNbConstraints ¶
GetNbConstraints returns the number of constraints
func (*System) GetNbInstructions ¶
func (*System) GetNbInternalVariables ¶
func (*System) GetNbPublicVariables ¶
func (*System) GetNbSecretVariables ¶
func (*System) GetNbVariables ¶
GetNbVariables return number of internal, secret and public variables
func (*System) VariableToString ¶
VariableToString implements Resolver
type Term ¶
type Term struct {
CID, VID uint32
}
Term represents a coeff * variable in a constraint system
func (*Term) IsConstant ¶
func (*Term) MarkConstant ¶
func (t *Term) MarkConstant()
type UnsatisfiedConstraintError ¶
type UnsatisfiedConstraintError struct { Err error CID int // constraint ID DebugInfo *string // optional debug info }
UnsatisfiedConstraintError wraps an error with useful metadata on the unsatisfied constraint
func (*UnsatisfiedConstraintError) Error ¶
func (r *UnsatisfiedConstraintError) Error() string