forked from Consensys/gnark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
orxorandmul.go
66 lines (54 loc) · 1.14 KB
/
orxorandmul.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
package circuits
import (
"github.com/aakash4dev/gnark2/frontend"
)
// circuit designed to test if plonk compiler recognizes
// correctly constraints of the form a*b=c where a is
// marked as boolean constraint, but the constraint doesn't exist
// (it's the case for the result of a XOR, OR, AND for instance)
type orXoAndMulCircuit struct {
A, B frontend.Variable
}
func (circuit *orXoAndMulCircuit) Define(api frontend.API) error {
a := api.Xor(circuit.A, circuit.B)
b := api.Mul(a, circuit.A)
c := api.Or(circuit.A, circuit.B)
d := api.Mul(c, circuit.A)
e := api.Or(circuit.A, circuit.B)
f := api.Mul(e, circuit.A)
api.AssertIsBoolean(b)
api.AssertIsBoolean(d)
api.AssertIsBoolean(f)
return nil
}
func init() {
good := []frontend.Circuit{
&orXoAndMulCircuit{
A: (1),
B: (1),
},
&orXoAndMulCircuit{
A: (1),
B: (0),
},
&orXoAndMulCircuit{
A: (0),
B: (1),
},
}
bad := []frontend.Circuit{
&orXoAndMulCircuit{
A: (0),
B: (2),
},
&orXoAndMulCircuit{
A: (2),
B: (0),
},
&orXoAndMulCircuit{
A: (1),
B: (2),
},
}
addNewEntry("orXoAndMulCircuit", &orXoAndMulCircuit{}, good, bad, nil)
}