-
Notifications
You must be signed in to change notification settings - Fork 353
/
blueprint.go
73 lines (60 loc) · 2.73 KB
/
blueprint.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package constraint
type BlueprintID uint32
// Blueprint enable representing heterogeneous 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 Blueprint interface {
// CalldataSize 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.
CalldataSize() int
// NbConstraints return the number of constraints this blueprint creates.
NbConstraints() int
// NbOutputs return the number of output wires this blueprint creates.
NbOutputs(inst Instruction) int
// WireWalker returns a function that walks the wires appearing in the blueprint.
// This is used by the level builder to build a dependency graph between instructions.
WireWalker(inst Instruction) func(cb func(wire uint32))
}
// 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 Solver interface {
Field
GetValue(cID, vID uint32) Element
GetCoeff(cID uint32) Element
SetValue(vID uint32, f Element)
IsSolved(vID uint32) bool
// Read interprets input calldata as a LinearExpression,
// evaluates it and return the result and the number of uint32 word read.
Read(calldata []uint32) (Element, int)
}
// BlueprintSolvable represents a blueprint that knows how to solve itself.
type BlueprintSolvable interface {
Blueprint
// Solve may return an error if the decoded constraint / calldata is unsolvable.
Solve(s Solver, instruction Instruction) error
}
// BlueprintR1C indicates that the blueprint and associated calldata encodes a R1C
type BlueprintR1C interface {
Blueprint
CompressR1C(c *R1C, to *[]uint32)
DecompressR1C(into *R1C, instruction Instruction)
}
// BlueprintSparseR1C indicates that the blueprint and associated calldata encodes a SparseR1C.
type BlueprintSparseR1C interface {
Blueprint
CompressSparseR1C(c *SparseR1C, to *[]uint32)
DecompressSparseR1C(into *SparseR1C, instruction Instruction)
}
// BlueprintHint indicates that the blueprint and associated calldata encodes a hint.
type BlueprintHint interface {
Blueprint
CompressHint(h HintMapping, to *[]uint32)
DecompressHint(h *HintMapping, instruction Instruction)
}
// Compressible represent an object that knows how to encode itself as a []uint32.
type Compressible interface {
// Compress interprets the objects as a LinearExpression and encodes it as a []uint32.
Compress(to *[]uint32)
}