-
Notifications
You must be signed in to change notification settings - Fork 9
/
circuit.go
47 lines (40 loc) · 1.05 KB
/
circuit.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
package gadget
import (
"github.com/AlexandreBelling/gnark/frontend"
)
// Interface to be implemented by any circuit willing to use Gkr
type CircuitUsingGkr interface {
Define(cs frontend.API, gadget *GkrGadget) error
}
// Generic wrapper circuit in which, we can plug any circuit using
// Gkr. The wrapper holds all the logic for the proving etc...
type Circuit struct {
Gadget GkrGadget
InnerCircuit CircuitUsingGkr
}
// Wraps the given circuit into a `Circuit` object
func WrapCircuitUsingGkr(c CircuitUsingGkr, opts ...GkrOption) Circuit {
w := Circuit{
InnerCircuit: c,
Gadget: *NewGkrGadget(),
}
// Applies the options
for _, opt := range opts {
opt(&w)
}
return w
}
// Implements `gnark`s circuit interface
func (c *Circuit) Define(cs frontend.API) error {
if err := c.InnerCircuit.Define(cs, &c.Gadget); err != nil {
return err
}
c.Gadget.Close(cs)
return nil
}
// Assigns for the subcircuit
func (c *Circuit) Assign() {
c.Gadget.InitialRandomness = 0
}
// Options for the `Circuit` constructor
type GkrOption func(c *Circuit)