Skip to content
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
12 changes: 6 additions & 6 deletions gnark/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.25.0
require (
github.com/consensys/gnark v0.14.0
github.com/consensys/gnark-crypto v0.19.2
golang.org/x/crypto v0.43.0
golang.org/x/crypto v0.45.0
)

require (
Expand All @@ -14,19 +14,19 @@ require (
)

require (
github.com/bits-and-blooms/bitset v1.24.3 // indirect
github.com/bits-and-blooms/bitset v1.24.4 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
github.com/google/pprof v0.0.0-20251007162407-5df77e3f7d1d // indirect
github.com/google/pprof v0.0.0-20251114195745-4902fdda35c8 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/ronanh/intcomp v1.1.1 // indirect
github.com/stretchr/testify v1.11.1
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
golang.org/x/sync v0.17.0 // indirect
golang.org/x/sys v0.37.0 // indirect
golang.org/x/exp v0.0.0-20251125195548-87e1e737ad39 // indirect
golang.org/x/sync v0.18.0 // indirect
golang.org/x/sys v0.38.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
24 changes: 12 additions & 12 deletions gnark/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/bits-and-blooms/bitset v1.24.3 h1:Bte86SlO3lwPQqww+7BE9ZuUCKIjfqnG5jtEyqA9y9Y=
github.com/bits-and-blooms/bitset v1.24.3/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
github.com/bits-and-blooms/bitset v1.24.4 h1:95H15Og1clikBrKr/DuzMXkQzECs1M6hhoGXLwLQOZE=
github.com/bits-and-blooms/bitset v1.24.4/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/consensys/gnark v0.14.0 h1:RG+8WxRanFSFBSlmCDRJnYMYYKpH3Ncs5SMzg24B5HQ=
Expand All @@ -14,8 +14,8 @@ github.com/fxamacker/cbor/v2 v2.9.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj2
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/pprof v0.0.0-20251007162407-5df77e3f7d1d h1:KJIErDwbSHjnp/SGzE5ed8Aol7JsKiI5X7yWKAtzhM0=
github.com/google/pprof v0.0.0-20251007162407-5df77e3f7d1d/go.mod h1:I6V7YzU0XDpsHqbsyrghnFZLO1gwK6NPTNvmetQIk9U=
github.com/google/pprof v0.0.0-20251114195745-4902fdda35c8 h1:3DsUAV+VNEQa2CUVLxCY3f87278uWfIDhJnbdvDjvmE=
github.com/google/pprof v0.0.0-20251114195745-4902fdda35c8/go.mod h1:I6V7YzU0XDpsHqbsyrghnFZLO1gwK6NPTNvmetQIk9U=
github.com/ingonyama-zk/icicle-gnark/v3 v3.2.2 h1:B+aWVgAx+GlFLhtYjIaF0uGjU3rzpl99Wf9wZWt+Mq8=
github.com/ingonyama-zk/icicle-gnark/v3 v3.2.2/go.mod h1:CH/cwcr21pPWH+9GtK/PFaa4OGTv4CtfkCKro6GpbRE=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
Expand Down Expand Up @@ -45,17 +45,17 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04=
golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
golang.org/x/exp v0.0.0-20251125195548-87e1e737ad39 h1:DHNhtq3sNNzrvduZZIiFyXWOL9IWaDPHqTnLJp+rCBY=
golang.org/x/exp v0.0.0-20251125195548-87e1e737ad39/go.mod h1:46edojNIoXTNOhySWIWdix628clX9ODXwPsQuG6hsK0=
golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I=
golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
111 changes: 46 additions & 65 deletions gnark/libraries/aux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package libraries
import (
"crypto/rand"
"encoding/json"
aes_v2 "github.com/reclaimprotocol/zk-symmetric-crypto/gnark/circuits/aesV2"
"github.com/reclaimprotocol/zk-symmetric-crypto/gnark/circuits/chachaV3"
prover "github.com/reclaimprotocol/zk-symmetric-crypto/gnark/libraries/prover/impl"
oprf2 "github.com/reclaimprotocol/zk-symmetric-crypto/gnark/libraries/prover/oprf"
verifier "github.com/reclaimprotocol/zk-symmetric-crypto/gnark/libraries/verifier/impl"
"fmt"
"math"
"math/big"
"os"
"sync"
"testing"

aes_v2 "github.com/reclaimprotocol/zk-symmetric-crypto/gnark/circuits/aesV2"
prover "github.com/reclaimprotocol/zk-symmetric-crypto/gnark/libraries/prover/impl"
oprf2 "github.com/reclaimprotocol/zk-symmetric-crypto/gnark/libraries/prover/oprf"
verifier "github.com/reclaimprotocol/zk-symmetric-crypto/gnark/libraries/verifier/impl"

"github.com/consensys/gnark/test"
)

Expand Down Expand Up @@ -144,68 +145,48 @@ func BenchmarkTOPRFFinalize(b *testing.B) {

func TestChaCha20RandomNoncesCounters(t *testing.T) {
assert := test.NewAssert(t)
assert.True(prover.InitAlgorithm(prover.CHACHA20, chachaKey, chachaR1CS))
bKey := make([]byte, 32)
bIn := make([]byte, 64*chachaV3.Blocks)

rand.Read(bKey)
rand.Read(bIn)

// Create truly random nonces and counters for each block
blocks := make([]prover.Block, chachaV3.Blocks)
for b := 0; b < chachaV3.Blocks; b++ {
nonce := make([]byte, 12)
rand.Read(nonce)
tmp, _ := rand.Int(rand.Reader, big.NewInt(math.MaxUint32))
counter := uint32(tmp.Uint64())
blocks[b] = prover.Block{
Nonce: nonce,
Counter: counter,
}
}

inputParams := &prover.InputParams{
Cipher: "chacha20",
Key: bKey,
Blocks: blocks,
Input: bIn,
}

buf, _ := json.Marshal(inputParams)
assert.True(prover.InitAlgorithm(prover.AES_128, aes128Key, aes128r1cs))

res := prover.Prove(buf)
j := `{
"cipher": "aes-128-ctr",
"key": "1WmuU/OkjNjfyZjT+wy+HQ==",
"ciphertext": "AKtju67OIJmJW1Ck2xZcqbJVvXR5G0LAZPdTzr0NCg0KTm0osuIC+G2KjKvdx5Hx8Dr95l52LtDw7vCT/xvM7WEUGoYMGAPFfDwlvLtvpjk=",
"blocks": [
{
"nonce": "et0QvQAAAAAAAAAB",
"counter": 32,
"boundary": null
},
{
"nonce": "et0QvQAAAAAAAAAB",
"counter": 33,
"boundary": null
},
{
"nonce": "et0QvQAAAAAAAAAB",
"counter": 34,
"boundary": null
},
{
"nonce": "et0QvQAAAAAAAAAB",
"counter": 35,
"boundary": null
},
{
"nonce": "et0QvQAAAAAAAAAB",
"counter": 36,
"boundary": null
}
],
"input": "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioYBQ+ZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"toprf": {

}
}`

res := prover.Prove([]byte(j))
assert.True(len(res) > 0)
var outParams *prover.OutputParams
json.Unmarshal(res, &outParams)

// Create verifier blocks
verifierBlocks := make([]verifier.Block, len(blocks))

for i, b := range blocks {
verifierBlocks[i] = verifier.Block{
Nonce: b.Nonce,
Counter: b.Counter,
}
}

// Create the new JSON structure for public signals
publicSignals := &verifier.PublicSignalsJSON{
Ciphertext: outParams.Ciphertext,
Blocks: verifierBlocks,
Input: bIn,
}

publicSignalsJSON, err := json.Marshal(publicSignals)
assert.NoError(err)

inParams := &verifier.InputVerifyParams{
Cipher: inputParams.Cipher,
Proof: outParams.Proof,
PublicSignals: publicSignalsJSON,
}
inBuf, err := json.Marshal(inParams)
assert.NoError(err)
assert.True(verifier.Verify(inBuf))
fmt.Println(string(res))
}

func TestAES128RandomNoncesCounters(t *testing.T) {
Expand Down
7 changes: 0 additions & 7 deletions gnark/libraries/prover/impl/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/backend/groth16"
"github.com/consensys/gnark/constraint"
"github.com/consensys/gnark/logger"
"github.com/consensys/gnark/std"
)

const (
Expand Down Expand Up @@ -80,11 +78,6 @@ type ProverParams struct {
initLock sync.Mutex
}

func init() {
logger.Disable()
std.RegisterHints()
}

func InitAlgorithm(algorithmID uint8, provingKey []byte, r1csData []byte) (res bool) {
defer func() {
if err := recover(); err != nil {
Expand Down
4 changes: 0 additions & 4 deletions gnark/libraries/prover/impl/provers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ import (
"golang.org/x/crypto/chacha20"
)

func init() {
// std.RegisterHints()
}

type TOPRFResponse struct {
Index uint8 `json:"index"`
PublicKeyShare []byte `json:"publicKeyShare"`
Expand Down
Loading