From a1112261517d4de600b965f8078120d1a2e04f17 Mon Sep 17 00:00:00 2001 From: Ivo Kubjas Date: Fri, 23 Aug 2024 09:23:00 +0000 Subject: [PATCH] refactor: move utils from std/ to internal --- constraint/bls12-377/gkr.go | 2 +- constraint/bls12-381/gkr.go | 2 +- constraint/bls24-315/gkr.go | 2 +- constraint/bls24-317/gkr.go | 2 +- constraint/bn254/gkr.go | 2 +- constraint/bw6-633/gkr.go | 2 +- constraint/bw6-761/gkr.go | 2 +- constraint/gkr.go | 5 +++-- {std/utils => internal}/algo_utils/algo_utils.go | 0 .../algo_utils/algo_utils_test.go | 0 .../backend/template/representations/gkr.go.tmpl | 2 +- std/compress/internal/io_test.go | 5 +++-- std/compress/internal/plonk/plonk_test.go | 7 ++++--- std/compress/io_test.go | 7 ++++--- std/compress/lzss/snark_test.go | 5 +++-- std/compress/lzss/snark_testing.go | 2 +- std/gkr/api.go | 2 +- std/gkr/api_test.go | 13 +++++++------ std/gkr/compile.go | 2 +- .../test_vectors_utils/test_vector_utils.go | 0 .../test_vectors_utils/test_vector_utils_test.go | 0 21 files changed, 35 insertions(+), 29 deletions(-) rename {std/utils => internal}/algo_utils/algo_utils.go (100%) rename {std/utils => internal}/algo_utils/algo_utils_test.go (100%) rename std/{utils => internal}/test_vectors_utils/test_vector_utils.go (100%) rename std/{utils => internal}/test_vectors_utils/test_vector_utils_test.go (100%) diff --git a/constraint/bls12-377/gkr.go b/constraint/bls12-377/gkr.go index 39f57003a5..ffb369fcac 100644 --- a/constraint/bls12-377/gkr.go +++ b/constraint/bls12-377/gkr.go @@ -25,7 +25,7 @@ import ( "github.com/consensys/gnark-crypto/utils" "github.com/consensys/gnark/constraint" hint "github.com/consensys/gnark/constraint/solver" - "github.com/consensys/gnark/std/utils/algo_utils" + "github.com/consensys/gnark/internal/algo_utils" "hash" "math/big" "sync" diff --git a/constraint/bls12-381/gkr.go b/constraint/bls12-381/gkr.go index 3c8cd75434..8480ebb6e8 100644 --- a/constraint/bls12-381/gkr.go +++ b/constraint/bls12-381/gkr.go @@ -25,7 +25,7 @@ import ( "github.com/consensys/gnark-crypto/utils" "github.com/consensys/gnark/constraint" hint "github.com/consensys/gnark/constraint/solver" - "github.com/consensys/gnark/std/utils/algo_utils" + "github.com/consensys/gnark/internal/algo_utils" "hash" "math/big" "sync" diff --git a/constraint/bls24-315/gkr.go b/constraint/bls24-315/gkr.go index a8d541a275..8205771038 100644 --- a/constraint/bls24-315/gkr.go +++ b/constraint/bls24-315/gkr.go @@ -25,7 +25,7 @@ import ( "github.com/consensys/gnark-crypto/utils" "github.com/consensys/gnark/constraint" hint "github.com/consensys/gnark/constraint/solver" - "github.com/consensys/gnark/std/utils/algo_utils" + "github.com/consensys/gnark/internal/algo_utils" "hash" "math/big" "sync" diff --git a/constraint/bls24-317/gkr.go b/constraint/bls24-317/gkr.go index ffe2ec1627..0894277205 100644 --- a/constraint/bls24-317/gkr.go +++ b/constraint/bls24-317/gkr.go @@ -25,7 +25,7 @@ import ( "github.com/consensys/gnark-crypto/utils" "github.com/consensys/gnark/constraint" hint "github.com/consensys/gnark/constraint/solver" - "github.com/consensys/gnark/std/utils/algo_utils" + "github.com/consensys/gnark/internal/algo_utils" "hash" "math/big" "sync" diff --git a/constraint/bn254/gkr.go b/constraint/bn254/gkr.go index 8e1ece3ca7..10de1207eb 100644 --- a/constraint/bn254/gkr.go +++ b/constraint/bn254/gkr.go @@ -25,7 +25,7 @@ import ( "github.com/consensys/gnark-crypto/utils" "github.com/consensys/gnark/constraint" hint "github.com/consensys/gnark/constraint/solver" - "github.com/consensys/gnark/std/utils/algo_utils" + "github.com/consensys/gnark/internal/algo_utils" "hash" "math/big" "sync" diff --git a/constraint/bw6-633/gkr.go b/constraint/bw6-633/gkr.go index f24ff2cb0b..41d58f19d5 100644 --- a/constraint/bw6-633/gkr.go +++ b/constraint/bw6-633/gkr.go @@ -25,7 +25,7 @@ import ( "github.com/consensys/gnark-crypto/utils" "github.com/consensys/gnark/constraint" hint "github.com/consensys/gnark/constraint/solver" - "github.com/consensys/gnark/std/utils/algo_utils" + "github.com/consensys/gnark/internal/algo_utils" "hash" "math/big" "sync" diff --git a/constraint/bw6-761/gkr.go b/constraint/bw6-761/gkr.go index c665d27dbc..585af422d4 100644 --- a/constraint/bw6-761/gkr.go +++ b/constraint/bw6-761/gkr.go @@ -25,7 +25,7 @@ import ( "github.com/consensys/gnark-crypto/utils" "github.com/consensys/gnark/constraint" hint "github.com/consensys/gnark/constraint/solver" - "github.com/consensys/gnark/std/utils/algo_utils" + "github.com/consensys/gnark/internal/algo_utils" "hash" "math/big" "sync" diff --git a/constraint/gkr.go b/constraint/gkr.go index 4d84a5466d..e1337cb0b9 100644 --- a/constraint/gkr.go +++ b/constraint/gkr.go @@ -2,10 +2,11 @@ package constraint import ( "fmt" + "sort" + "github.com/consensys/gnark-crypto/utils" "github.com/consensys/gnark/constraint/solver" - "github.com/consensys/gnark/std/utils/algo_utils" - "sort" + "github.com/consensys/gnark/internal/algo_utils" ) type GkrVariable int // Just an alias to hide implementation details. May be more trouble than worth diff --git a/std/utils/algo_utils/algo_utils.go b/internal/algo_utils/algo_utils.go similarity index 100% rename from std/utils/algo_utils/algo_utils.go rename to internal/algo_utils/algo_utils.go diff --git a/std/utils/algo_utils/algo_utils_test.go b/internal/algo_utils/algo_utils_test.go similarity index 100% rename from std/utils/algo_utils/algo_utils_test.go rename to internal/algo_utils/algo_utils_test.go diff --git a/internal/generator/backend/template/representations/gkr.go.tmpl b/internal/generator/backend/template/representations/gkr.go.tmpl index 3801ce0de5..32ff5da874 100644 --- a/internal/generator/backend/template/representations/gkr.go.tmpl +++ b/internal/generator/backend/template/representations/gkr.go.tmpl @@ -7,7 +7,7 @@ import ( "github.com/consensys/gnark-crypto/utils" "github.com/consensys/gnark/constraint" hint "github.com/consensys/gnark/constraint/solver" - "github.com/consensys/gnark/std/utils/algo_utils" + "github.com/consensys/gnark/internal/algo_utils" "hash" "math/big" "sync" diff --git a/std/compress/internal/io_test.go b/std/compress/internal/io_test.go index 1745970bd3..f88b9cc0fa 100644 --- a/std/compress/internal/io_test.go +++ b/std/compress/internal/io_test.go @@ -3,6 +3,8 @@ package internal_test import ( "bytes" "crypto/rand" + "testing" + "github.com/consensys/gnark-crypto/ecc" "github.com/consensys/gnark/backend" "github.com/consensys/gnark/frontend" @@ -10,12 +12,11 @@ import ( "github.com/consensys/gnark/std/compress" "github.com/consensys/gnark/std/compress/internal" "github.com/consensys/gnark/std/compress/lzss" + test_vector_utils "github.com/consensys/gnark/std/internal/test_vectors_utils" "github.com/consensys/gnark/std/math/bits" - test_vector_utils "github.com/consensys/gnark/std/utils/test_vectors_utils" "github.com/consensys/gnark/test" "github.com/icza/bitio" "github.com/stretchr/testify/assert" - "testing" ) func TestRecombineBytes(t *testing.T) { diff --git a/std/compress/internal/plonk/plonk_test.go b/std/compress/internal/plonk/plonk_test.go index 1023d1ee2a..7392139f17 100644 --- a/std/compress/internal/plonk/plonk_test.go +++ b/std/compress/internal/plonk/plonk_test.go @@ -4,14 +4,15 @@ import ( "crypto/rand" "encoding/binary" "errors" + "reflect" + "testing" + "github.com/consensys/gnark-crypto/ecc" "github.com/consensys/gnark-crypto/ecc/bls12-377/fr" "github.com/consensys/gnark/backend" "github.com/consensys/gnark/frontend" - test_vector_utils "github.com/consensys/gnark/std/utils/test_vectors_utils" + test_vector_utils "github.com/consensys/gnark/std/internal/test_vectors_utils" "github.com/consensys/gnark/test" - "reflect" - "testing" ) func TestCustomConstraint(t *testing.T) { diff --git a/std/compress/io_test.go b/std/compress/io_test.go index cbe17e7a73..ea07eeb1ae 100644 --- a/std/compress/io_test.go +++ b/std/compress/io_test.go @@ -4,6 +4,9 @@ import ( "crypto/rand" "errors" "fmt" + "math/big" + "testing" + "github.com/consensys/gnark-crypto/ecc" "github.com/consensys/gnark-crypto/ecc/bls12-377/fr" "github.com/consensys/gnark-crypto/hash" @@ -11,11 +14,9 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/frontend/cs/scs" "github.com/consensys/gnark/profile" - test_vector_utils "github.com/consensys/gnark/std/utils/test_vectors_utils" + test_vector_utils "github.com/consensys/gnark/std/internal/test_vectors_utils" "github.com/consensys/gnark/test" "github.com/stretchr/testify/assert" - "math/big" - "testing" ) func TestShiftLeft(t *testing.T) { diff --git a/std/compress/lzss/snark_test.go b/std/compress/lzss/snark_test.go index ab1fbfc232..34936dd73b 100644 --- a/std/compress/lzss/snark_test.go +++ b/std/compress/lzss/snark_test.go @@ -4,15 +4,16 @@ import ( "crypto/sha256" "encoding/hex" "fmt" - "github.com/consensys/gnark/frontend/cs/scs" "os" "testing" + "github.com/consensys/gnark/frontend/cs/scs" + "github.com/consensys/compress/lzss" "github.com/consensys/gnark-crypto/ecc" "github.com/consensys/gnark/backend" "github.com/consensys/gnark/frontend" - test_vector_utils "github.com/consensys/gnark/std/utils/test_vectors_utils" + test_vector_utils "github.com/consensys/gnark/std/internal/test_vectors_utils" "github.com/consensys/gnark/test" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/std/compress/lzss/snark_testing.go b/std/compress/lzss/snark_testing.go index a224898c86..fc309a3fd8 100644 --- a/std/compress/lzss/snark_testing.go +++ b/std/compress/lzss/snark_testing.go @@ -4,7 +4,7 @@ import ( "github.com/consensys/compress/lzss" "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/std/compress" - test_vector_utils "github.com/consensys/gnark/std/utils/test_vectors_utils" + test_vector_utils "github.com/consensys/gnark/std/internal/test_vectors_utils" ) type DecompressionTestCircuit struct { diff --git a/std/gkr/api.go b/std/gkr/api.go index d13c65e2d0..b46cfad8e5 100644 --- a/std/gkr/api.go +++ b/std/gkr/api.go @@ -2,7 +2,7 @@ package gkr import ( "github.com/consensys/gnark/constraint" - "github.com/consensys/gnark/std/utils/algo_utils" + "github.com/consensys/gnark/internal/algo_utils" ) func frontendVarToInt(a constraint.GkrVariable) int { diff --git a/std/gkr/api_test.go b/std/gkr/api_test.go index 2dead41af5..25fc3c3c1e 100644 --- a/std/gkr/api_test.go +++ b/std/gkr/api_test.go @@ -2,6 +2,12 @@ package gkr import ( "fmt" + "hash" + "math/rand" + "strconv" + "testing" + "time" + bls12377 "github.com/consensys/gnark/constraint/bls12-377" bls12381 "github.com/consensys/gnark/constraint/bls12-381" bls24315 "github.com/consensys/gnark/constraint/bls24-315" @@ -9,11 +15,6 @@ import ( bw6633 "github.com/consensys/gnark/constraint/bw6-633" bw6761 "github.com/consensys/gnark/constraint/bw6-761" "github.com/consensys/gnark/test" - "hash" - "math/rand" - "strconv" - "testing" - "time" "github.com/consensys/gnark-crypto/kzg" "github.com/consensys/gnark/backend/plonk" @@ -32,7 +33,7 @@ import ( "github.com/consensys/gnark/frontend/cs/scs" stdHash "github.com/consensys/gnark/std/hash" "github.com/consensys/gnark/std/hash/mimc" - test_vector_utils "github.com/consensys/gnark/std/utils/test_vectors_utils" + test_vector_utils "github.com/consensys/gnark/std/internal/test_vectors_utils" "github.com/consensys/gnark/test/unsafekzg" ) diff --git a/std/gkr/compile.go b/std/gkr/compile.go index 72a60570ba..dd3ad75ee0 100644 --- a/std/gkr/compile.go +++ b/std/gkr/compile.go @@ -7,9 +7,9 @@ import ( "github.com/consensys/gnark/constraint" "github.com/consensys/gnark/constraint/solver" "github.com/consensys/gnark/frontend" + "github.com/consensys/gnark/internal/algo_utils" fiatshamir "github.com/consensys/gnark/std/fiat-shamir" "github.com/consensys/gnark/std/hash" - "github.com/consensys/gnark/std/utils/algo_utils" ) type circuitDataForSnark struct { diff --git a/std/utils/test_vectors_utils/test_vector_utils.go b/std/internal/test_vectors_utils/test_vector_utils.go similarity index 100% rename from std/utils/test_vectors_utils/test_vector_utils.go rename to std/internal/test_vectors_utils/test_vector_utils.go diff --git a/std/utils/test_vectors_utils/test_vector_utils_test.go b/std/internal/test_vectors_utils/test_vector_utils_test.go similarity index 100% rename from std/utils/test_vectors_utils/test_vector_utils_test.go rename to std/internal/test_vectors_utils/test_vector_utils_test.go