github.com/consensys/gnark@v0.11.0/constraint/system.go (about) 1 package constraint 2 3 import ( 4 "io" 5 "math/big" 6 7 "github.com/consensys/gnark/backend/witness" 8 "github.com/consensys/gnark/constraint/solver" 9 ) 10 11 // ConstraintSystem interface that all constraint systems implement. 12 type ConstraintSystem interface { 13 io.WriterTo 14 io.ReaderFrom 15 Field 16 Resolver 17 CustomizableSystem 18 19 // IsSolved returns nil if given witness solves the constraint system and error otherwise 20 // Deprecated: use _, err := Solve(...) instead 21 IsSolved(witness witness.Witness, opts ...solver.Option) error 22 23 // Solve attempts to solve the constraint system using provided witness. 24 // Returns an error if the witness does not allow all the constraints to be satisfied. 25 // Returns a typed solution (R1CSSolution or SparseR1CSSolution) and nil otherwise. 26 Solve(witness witness.Witness, opts ...solver.Option) (any, error) 27 28 // GetNbVariables return number of internal, secret and public Variables 29 // Deprecated: use GetNbSecretVariables() instead 30 GetNbVariables() (internal, secret, public int) 31 32 GetNbInternalVariables() int 33 GetNbSecretVariables() int 34 GetNbPublicVariables() int 35 36 GetNbInstructions() int 37 GetNbConstraints() int 38 GetNbCoefficients() int 39 40 Field() *big.Int 41 FieldBitLen() int 42 43 AddPublicVariable(name string) int 44 AddSecretVariable(name string) int 45 AddInternalVariable() int 46 47 // AddSolverHint adds a hint to the solver such that the output variables will be computed 48 // using a call to output := f(input...) at solve time. 49 // Providing the function f is optional. If it is provided, id will be ignored and one will be derived from f's name. 50 // Otherwise, the provided id will be used to register the hint with, 51 AddSolverHint(f solver.Hint, id solver.HintID, input []LinearExpression, nbOutput int) (internalVariables []int, err error) 52 53 AddCommitment(c Commitment) error 54 GetCommitments() Commitments 55 AddGkr(gkr GkrInfo) error 56 57 AddLog(l LogEntry) 58 59 // MakeTerm returns a new Term. The constraint system may store coefficients in a map, so 60 // calls to this function will grow the memory usage of the constraint system. 61 MakeTerm(coeff Element, variableID int) Term 62 63 // AddCoeff adds a coefficient to the underlying constraint system. The system will not store duplicate, 64 // but is not purging for unused coeff either, so this grows memory usage. 65 AddCoeff(coeff Element) uint32 66 67 NewDebugInfo(errName string, i ...interface{}) DebugInfo 68 69 // AttachDebugInfo enables attaching debug information to multiple constraints. 70 // This is more efficient than using the AddR1C(.., debugInfo) since it will store the 71 // debug information only once. 72 AttachDebugInfo(debugInfo DebugInfo, constraintID []int) 73 74 // CheckUnconstrainedWires returns and error if the constraint system has wires that are not uniquely constrained. 75 // This is experimental. 76 CheckUnconstrainedWires() error 77 78 GetInstruction(int) Instruction 79 80 GetCoefficient(i int) Element 81 } 82 83 type CustomizableSystem interface { 84 // AddBlueprint registers the given blueprint and returns its id. This should be called only once per blueprint. 85 AddBlueprint(b Blueprint) BlueprintID 86 87 // AddInstruction adds an instruction to the system and returns a list of created wires 88 // if the blueprint declared any outputs. 89 AddInstruction(bID BlueprintID, calldata []uint32) []uint32 90 }