Skip to content

Commit a0e0056

Browse files
authored
GKR Gate Registry (#1442)
1 parent b51a3d4 commit a0e0056

File tree

29 files changed

+592
-330
lines changed

29 files changed

+592
-330
lines changed

constraint/bls12-377/gkr.go

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

constraint/bls12-381/gkr.go

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

constraint/bls24-315/gkr.go

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

constraint/bls24-317/gkr.go

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

constraint/bn254/gkr.go

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

constraint/bw6-633/gkr.go

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

constraint/bw6-761/gkr.go

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ type API interface {
124124
// [github.com/consensys/gnark/std/math/bits].
125125
AssertIsLessOrEqual(v Variable, bound Variable)
126126

127-
// Println behaves like fmt.Println but accepts cd.Variable as parameter
127+
// Println behaves like fmt.Println but accepts frontend.Variable as parameter
128128
// whose value will be resolved at runtime when computed by the solver
129129
Println(a ...Variable)
130130

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ toolchain go1.22.6
77
require (
88
github.com/bits-and-blooms/bitset v1.20.0
99
github.com/blang/semver/v4 v4.0.0
10-
github.com/consensys/bavard v0.1.29
10+
github.com/consensys/bavard v0.1.31-0.20250314194434-b30d4344e6d4
1111
github.com/consensys/compress v0.2.5
12-
github.com/consensys/gnark-crypto v0.16.1-0.20250217214835-5ed804970f85
12+
github.com/consensys/gnark-crypto v0.17.1-0.20250326164229-5fd6610ac2a1
1313
github.com/fxamacker/cbor/v2 v2.7.0
1414
github.com/google/go-cmp v0.6.0
1515
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
5757
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
5858
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
5959
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
60-
github.com/consensys/bavard v0.1.29 h1:fobxIYksIQ+ZSrTJUuQgu+HIJwclrAPcdXqd7H2hh1k=
61-
github.com/consensys/bavard v0.1.29/go.mod h1:k/zVjHHC4B+PQy1Pg7fgvG3ALicQw540Crag8qx+dZs=
60+
github.com/consensys/bavard v0.1.31-0.20250314194434-b30d4344e6d4 h1:0J+ppRic2ZXsQE+Y+Lr9miam+RQVcWqwqe3SeiggR6s=
61+
github.com/consensys/bavard v0.1.31-0.20250314194434-b30d4344e6d4/go.mod h1:k/zVjHHC4B+PQy1Pg7fgvG3ALicQw540Crag8qx+dZs=
6262
github.com/consensys/compress v0.2.5 h1:gJr1hKzbOD36JFsF1AN8lfXz1yevnJi1YolffY19Ntk=
6363
github.com/consensys/compress v0.2.5/go.mod h1:pyM+ZXiNUh7/0+AUjUf9RKUM6vSH7T/fsn5LLS0j1Tk=
64-
github.com/consensys/gnark-crypto v0.16.1-0.20250217214835-5ed804970f85 h1:3ht4gGH3smFGVLFhpFTKvDbEdagC6eSaPXnHjCQGh94=
65-
github.com/consensys/gnark-crypto v0.16.1-0.20250217214835-5ed804970f85/go.mod h1:A2URlMHUT81ifJ0UlLzSlm7TmnE3t7VxEThApdMukJw=
64+
github.com/consensys/gnark-crypto v0.17.1-0.20250326164229-5fd6610ac2a1 h1:6cK71BoMAjWHNl+EpvBh2PDDa0PIeoz1KFJ/6R16DjQ=
65+
github.com/consensys/gnark-crypto v0.17.1-0.20250326164229-5fd6610ac2a1/go.mod h1:uV1HwfBwGRj50DGK3LbDLeCvq0RX/vFXST3CRSAu0Fs=
6666
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
6767
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
6868
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=

internal/generator/backend/template/representations/gkr.go.tmpl

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ type GkrSolvingData struct {
2222

2323
func convertCircuit(noPtr constraint.GkrCircuit) (gkr.Circuit, error) {
2424
resCircuit := make(gkr.Circuit, len(noPtr))
25-
var found bool
2625
for i := range noPtr {
27-
if resCircuit[i].Gate, found = gkr.Gates[noPtr[i].Gate]; !found && noPtr[i].Gate != "" {
26+
if resCircuit[i].Gate = gkr.GetGate(gkr.GateName(noPtr[i].Gate)); resCircuit[i].Gate == nil && noPtr[i].Gate != "" {
2827
return nil, fmt.Errorf("gate \"%s\" not found", noPtr[i].Gate)
2928
}
3029
resCircuit[i].Inputs = algo_utils.Map(noPtr[i].Inputs, algo_utils.SlicePtrAt(resCircuit))

internal/tinyfield/element.go

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/tinyfield/element_test.go

+25-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/tinyfield/vector.go

+24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/tinyfield/vector_test.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

std/gkr/api.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ func frontendVarToInt(a constraint.GkrVariable) int {
99
return int(a)
1010
}
1111

12-
func (api *API) NamedGate(gate string, in ...constraint.GkrVariable) constraint.GkrVariable {
12+
func (api *API) NamedGate(gate GateName, in ...constraint.GkrVariable) constraint.GkrVariable {
1313
api.toStore.Circuit = append(api.toStore.Circuit, constraint.GkrWire{
14-
Gate: gate,
14+
Gate: string(gate),
1515
Inputs: utils.Map(in, frontendVarToInt),
1616
})
1717
api.assignments = append(api.assignments, nil)
1818
return constraint.GkrVariable(len(api.toStore.Circuit) - 1)
1919
}
2020

21-
func (api *API) namedGate2PlusIn(gate string, in1, in2 constraint.GkrVariable, in ...constraint.GkrVariable) constraint.GkrVariable {
21+
func (api *API) namedGate2PlusIn(gate GateName, in1, in2 constraint.GkrVariable, in ...constraint.GkrVariable) constraint.GkrVariable {
2222
inCombined := make([]constraint.GkrVariable, 2+len(in))
2323
inCombined[0] = in1
2424
inCombined[1] = in2
@@ -28,18 +28,18 @@ func (api *API) namedGate2PlusIn(gate string, in1, in2 constraint.GkrVariable, i
2828
return api.NamedGate(gate, inCombined...)
2929
}
3030

31-
func (api *API) Add(i1, i2 constraint.GkrVariable, in ...constraint.GkrVariable) constraint.GkrVariable {
32-
return api.namedGate2PlusIn("add", i1, i2, in...)
31+
func (api *API) Add(i1, i2 constraint.GkrVariable) constraint.GkrVariable {
32+
return api.namedGate2PlusIn(Add2, i1, i2)
3333
}
3434

3535
func (api *API) Neg(i1 constraint.GkrVariable) constraint.GkrVariable {
3636
return api.NamedGate("neg", i1)
3737
}
3838

39-
func (api *API) Sub(i1, i2 constraint.GkrVariable, in ...constraint.GkrVariable) constraint.GkrVariable {
40-
return api.namedGate2PlusIn("sub", i1, i2, in...)
39+
func (api *API) Sub(i1, i2 constraint.GkrVariable) constraint.GkrVariable {
40+
return api.namedGate2PlusIn(Sub2, i1, i2)
4141
}
4242

43-
func (api *API) Mul(i1, i2 constraint.GkrVariable, in ...constraint.GkrVariable) constraint.GkrVariable {
44-
return api.namedGate2PlusIn("mul", i1, i2, in...)
43+
func (api *API) Mul(i1, i2 constraint.GkrVariable) constraint.GkrVariable {
44+
return api.namedGate2PlusIn(Mul2, i1, i2)
4545
}

0 commit comments

Comments
 (0)