Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GKR Gate Registry #1442

Merged
merged 17 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions constraint/bls12-377/gkr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions constraint/bls12-381/gkr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions constraint/bls24-315/gkr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions constraint/bls24-317/gkr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions constraint/bn254/gkr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions constraint/bw6-633/gkr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions constraint/bw6-761/gkr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ type API interface {
// [github.com/consensys/gnark/std/math/bits].
AssertIsLessOrEqual(v Variable, bound Variable)

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

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ toolchain go1.22.6
require (
github.com/bits-and-blooms/bitset v1.20.0
github.com/blang/semver/v4 v4.0.0
github.com/consensys/bavard v0.1.29
github.com/consensys/bavard v0.1.31-0.20250314194434-b30d4344e6d4
github.com/consensys/compress v0.2.5
github.com/consensys/gnark-crypto v0.16.1-0.20250217214835-5ed804970f85
github.com/consensys/gnark-crypto v0.17.1-0.20250326164229-5fd6610ac2a1
github.com/fxamacker/cbor/v2 v2.7.0
github.com/google/go-cmp v0.6.0
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/consensys/bavard v0.1.29 h1:fobxIYksIQ+ZSrTJUuQgu+HIJwclrAPcdXqd7H2hh1k=
github.com/consensys/bavard v0.1.29/go.mod h1:k/zVjHHC4B+PQy1Pg7fgvG3ALicQw540Crag8qx+dZs=
github.com/consensys/bavard v0.1.31-0.20250314194434-b30d4344e6d4 h1:0J+ppRic2ZXsQE+Y+Lr9miam+RQVcWqwqe3SeiggR6s=
github.com/consensys/bavard v0.1.31-0.20250314194434-b30d4344e6d4/go.mod h1:k/zVjHHC4B+PQy1Pg7fgvG3ALicQw540Crag8qx+dZs=
github.com/consensys/compress v0.2.5 h1:gJr1hKzbOD36JFsF1AN8lfXz1yevnJi1YolffY19Ntk=
github.com/consensys/compress v0.2.5/go.mod h1:pyM+ZXiNUh7/0+AUjUf9RKUM6vSH7T/fsn5LLS0j1Tk=
github.com/consensys/gnark-crypto v0.16.1-0.20250217214835-5ed804970f85 h1:3ht4gGH3smFGVLFhpFTKvDbEdagC6eSaPXnHjCQGh94=
github.com/consensys/gnark-crypto v0.16.1-0.20250217214835-5ed804970f85/go.mod h1:A2URlMHUT81ifJ0UlLzSlm7TmnE3t7VxEThApdMukJw=
github.com/consensys/gnark-crypto v0.17.1-0.20250326164229-5fd6610ac2a1 h1:6cK71BoMAjWHNl+EpvBh2PDDa0PIeoz1KFJ/6R16DjQ=
github.com/consensys/gnark-crypto v0.17.1-0.20250326164229-5fd6610ac2a1/go.mod h1:uV1HwfBwGRj50DGK3LbDLeCvq0RX/vFXST3CRSAu0Fs=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ type GkrSolvingData struct {

func convertCircuit(noPtr constraint.GkrCircuit) (gkr.Circuit, error) {
resCircuit := make(gkr.Circuit, len(noPtr))
var found bool
for i := range noPtr {
if resCircuit[i].Gate, found = gkr.Gates[noPtr[i].Gate]; !found && noPtr[i].Gate != "" {
if resCircuit[i].Gate = gkr.GetGate(gkr.GateName(noPtr[i].Gate)); resCircuit[i].Gate == nil && noPtr[i].Gate != "" {
return nil, fmt.Errorf("gate \"%s\" not found", noPtr[i].Gate)
}
resCircuit[i].Inputs = algo_utils.Map(noPtr[i].Inputs, algo_utils.SlicePtrAt(resCircuit))
Expand Down
10 changes: 10 additions & 0 deletions internal/tinyfield/element.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 25 additions & 25 deletions internal/tinyfield/element_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions internal/tinyfield/vector.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/tinyfield/vector_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions std/gkr/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ func frontendVarToInt(a constraint.GkrVariable) int {
return int(a)
}

func (api *API) NamedGate(gate string, in ...constraint.GkrVariable) constraint.GkrVariable {
func (api *API) NamedGate(gate GateName, in ...constraint.GkrVariable) constraint.GkrVariable {
api.toStore.Circuit = append(api.toStore.Circuit, constraint.GkrWire{
Gate: gate,
Gate: string(gate),
Inputs: utils.Map(in, frontendVarToInt),
})
api.assignments = append(api.assignments, nil)
return constraint.GkrVariable(len(api.toStore.Circuit) - 1)
}

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

func (api *API) Add(i1, i2 constraint.GkrVariable, in ...constraint.GkrVariable) constraint.GkrVariable {
return api.namedGate2PlusIn("add", i1, i2, in...)
func (api *API) Add(i1, i2 constraint.GkrVariable) constraint.GkrVariable {
return api.namedGate2PlusIn(Add2, i1, i2)
}

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

func (api *API) Sub(i1, i2 constraint.GkrVariable, in ...constraint.GkrVariable) constraint.GkrVariable {
return api.namedGate2PlusIn("sub", i1, i2, in...)
func (api *API) Sub(i1, i2 constraint.GkrVariable) constraint.GkrVariable {
return api.namedGate2PlusIn(Sub2, i1, i2)
}

func (api *API) Mul(i1, i2 constraint.GkrVariable, in ...constraint.GkrVariable) constraint.GkrVariable {
return api.namedGate2PlusIn("mul", i1, i2, in...)
func (api *API) Mul(i1, i2 constraint.GkrVariable) constraint.GkrVariable {
return api.namedGate2PlusIn(Mul2, i1, i2)
}
Loading