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
38 changes: 18 additions & 20 deletions go-sdk/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@ module github.com/hyperledger-labs/zeto/go-sdk
go 1.24.4

require (
github.com/ethereum/go-ethereum v1.16.3
github.com/iden3/go-rapidsnark/witness/wasmer v0.0.0-20250114164021-779c4f7dbadd
github.com/ethereum/go-ethereum v1.16.7
github.com/iden3/go-rapidsnark/witness/wasmer v0.0.0-20251113130218-15cc9f587b90
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.11.1
github.com/x-cray/logrus-prefixed-formatter v0.5.2
)

require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20251208031133-be43a854e4be // indirect
github.com/aidarkhanov/nanoid v1.0.8 // indirect
github.com/bits-and-blooms/bitset v1.24.0 // indirect
github.com/bits-and-blooms/bitset v1.24.4 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/consensys/gnark-crypto v0.19.0 // indirect
github.com/consensys/gnark-crypto v0.19.2 // indirect
github.com/crate-crypto/go-eth-kzg v1.4.0 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
github.com/deckarep/golang-set/v2 v2.8.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/ethereum/c-kzg-4844/v2 v2.1.2 // indirect
github.com/ethereum/c-kzg-4844/v2 v2.1.5 // indirect
github.com/ethereum/go-verkle v0.2.2 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/holiman/uint256 v1.3.2 // indirect
github.com/hyperledger/firefly-common v1.4.6 // indirect
github.com/hyperledger/firefly-common v1.5.9 // indirect
github.com/iden3/wasmer-go v0.0.1 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
Expand All @@ -44,32 +44,30 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/supranational/blst v0.3.15 // indirect
github.com/tklauser/go-sysconf v0.3.15 // indirect
github.com/tklauser/numcpus v0.10.0 // indirect
github.com/supranational/blst v0.3.16 // indirect
github.com/tklauser/go-sysconf v0.3.16 // indirect
github.com/tklauser/numcpus v0.11.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
golang.org/x/net v0.44.0 // indirect
golang.org/x/sync v0.17.0 // indirect
golang.org/x/term v0.35.0 // indirect
golang.org/x/text v0.29.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/term v0.38.0 // indirect
golang.org/x/text v0.32.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
)

require (
github.com/cloudflare/circl v1.6.1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dchest/blake512 v1.0.0 // indirect
github.com/hyperledger/firefly-signer v1.1.13
github.com/hyperledger/firefly-signer v1.1.22
github.com/iden3/go-iden3-crypto v0.0.17
github.com/iden3/go-rapidsnark/prover v0.0.13
github.com/iden3/go-rapidsnark/prover v0.0.15
github.com/iden3/go-rapidsnark/types v0.0.3
github.com/iden3/go-rapidsnark/verifier v0.0.5
github.com/iden3/go-rapidsnark/witness/v2 v2.0.0
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
golang.org/x/crypto v0.42.0 // indirect
golang.org/x/sys v0.36.0 // indirect
golang.org/x/crypto v0.46.0
golang.org/x/sys v0.39.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/postgres v1.5.9
gorm.io/driver/sqlite v1.6.0
gorm.io/gorm v1.31.0
gorm.io/gorm v1.31.1
)
214 changes: 105 additions & 109 deletions go-sdk/go.sum

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion go-sdk/integration-test/common/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"testing"

"github.com/hyperledger-labs/zeto/go-sdk/internal/crypto/hash"
"github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/core"
"github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/storage"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -36,7 +37,7 @@ func NewSqliteStorage(t *testing.T) (*os.File, core.Storage, *gorm.DB, string) {
assert.NoError(t, err)

provider := &TestSqlProvider{Db: db}
sqlStorage, err := storage.NewSqlStorage(provider, testName)
sqlStorage, err := storage.NewSqlStorage(provider, testName, &hash.PoseidonHasher{})
assert.NoError(t, err)
return dbfile, sqlStorage, db, testName
}
5 changes: 3 additions & 2 deletions go-sdk/integration-test/common/smt.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"math/big"
"testing"

"github.com/hyperledger-labs/zeto/go-sdk/internal/crypto/hash"
"github.com/hyperledger-labs/zeto/go-sdk/internal/sparse-merkle-tree/smt"
"github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/core"
"github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/node"
Expand Down Expand Up @@ -38,9 +39,9 @@ func BuildMerkleProofs(inputCommitments []*big.Int, db core.Storage, t *testing.
}

func AddCommitmentToMerkleTree(mt core.SparseMerkleTree, commitment *big.Int, t *testing.T) {
idx, _ := node.NewNodeIndexFromBigInt(commitment)
idx, _ := node.NewNodeIndexFromBigInt(commitment, &hash.PoseidonHasher{})
utxo := node.NewIndexOnly(idx)
n, err := node.NewLeafNode(utxo)
n, err := node.NewLeafNode(utxo, nil)
assert.NoError(t, err)
err = mt.AddLeaf(n)
assert.NoError(t, err)
Expand Down
14 changes: 9 additions & 5 deletions go-sdk/integration-test/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import (
"testing"

"github.com/hyperledger-labs/zeto/go-sdk/integration-test/common"
"github.com/hyperledger-labs/zeto/go-sdk/internal/crypto/hash"
"github.com/hyperledger-labs/zeto/go-sdk/internal/testutils"
"github.com/hyperledger-labs/zeto/go-sdk/pkg/crypto"

"github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/core"
"github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/node"
"github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/smt"
Expand Down Expand Up @@ -54,6 +56,7 @@ func (s *SqliteTestSuite) TearDownTest() {
}

func (s *SqliteTestSuite) TestSqliteStorage() {
hasher := crypto.NewPoseidonHasher()
mt, err := smt.NewMerkleTree(s.db, common.MAX_HEIGHT)
assert.NoError(s.T(), err)

Expand All @@ -63,8 +66,8 @@ func (s *SqliteTestSuite) TestSqliteStorage() {
sender := testutils.NewKeypair()
salt1 := crypto.NewSalt()

utxo1 := node.NewNonFungible(tokenId, uriString, sender.PublicKey, salt1)
n1, err := node.NewLeafNode(utxo1)
utxo1 := node.NewNonFungible(tokenId, uriString, sender.PublicKey, salt1, hasher)
n1, err := node.NewLeafNode(utxo1, nil)
assert.NoError(s.T(), err)
err = mt.AddLeaf(n1)
assert.NoError(s.T(), err)
Expand Down Expand Up @@ -103,9 +106,10 @@ func TestPostgresStorage(t *testing.T) {
}()

provider := &common.TestSqlProvider{Db: db}
s, err := storage.NewSqlStorage(provider, "test_1")
s, err := storage.NewSqlStorage(provider, "test_1", &hash.PoseidonHasher{})
assert.NoError(t, err)

hasher := crypto.NewPoseidonHasher()
mt, err := smt.NewMerkleTree(s, common.MAX_HEIGHT)
assert.NoError(t, err)

Expand All @@ -115,8 +119,8 @@ func TestPostgresStorage(t *testing.T) {
sender := testutils.NewKeypair()
salt1 := crypto.NewSalt()

utxo1 := node.NewNonFungible(tokenId, tokenUri, sender.PublicKey, salt1)
n1, err := node.NewLeafNode(utxo1)
utxo1 := node.NewNonFungible(tokenId, tokenUri, sender.PublicKey, salt1, hasher)
n1, err := node.NewLeafNode(utxo1, nil)
assert.NoError(t, err)
err = mt.AddLeaf(n1)
assert.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion go-sdk/integration-test/e2e_anon_nullifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ func (s *E2ETestSuite) TestZeto_anon_nullifier_locked_SuccessfulProving() {
senderEthAddress, ok := new(big.Int).SetString("5d093e9b41911be5f5c4cf91b108bac5d130fa83", 16)
assert.True(s.T(), ok)
_, db, _, _ := common.NewSqliteStorage(s.T())
hasher := crypto.NewPoseidonHasher()
mt, err := smt.NewMerkleTree(db, common.MAX_HEIGHT)
assert.NoError(s.T(), err)

for i, value := range s.regularTest.InputValues {
utxo := node.NewFungible(value, s.sender.PublicKey, s.regularTest.InputSalts[i])
utxo := node.NewFungible(value, s.sender.PublicKey, s.regularTest.InputSalts[i], hasher)
n, err := node.NewLeafNode(utxo, senderEthAddress)
assert.NoError(s.T(), err)
err = mt.AddLeaf(n)
Expand Down
5 changes: 3 additions & 2 deletions go-sdk/integration-test/e2e_nf_anon_nullifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ func (s *E2ETestSuite) TestZeto_nf_anon_nullifier_SuccessfulProving() {

nullifier1, _ := poseidon.Hash([]*big.Int{tokenId, tokenUri, salt1, sender.PrivateKeyBigInt})

hasher := crypto.NewPoseidonHasher()
mt, err := smt.NewMerkleTree(s.db, common.MAX_HEIGHT)
assert.NoError(s.T(), err)
utxo1 := node.NewNonFungible(tokenId, uriString, sender.PublicKey, salt1)
n1, err := node.NewLeafNode(utxo1)
utxo1 := node.NewNonFungible(tokenId, uriString, sender.PublicKey, salt1, hasher)
n1, err := node.NewLeafNode(utxo1, nil)
assert.NoError(s.T(), err)
err = mt.AddLeaf(n1)
assert.NoError(s.T(), err)
Expand Down
2 changes: 1 addition & 1 deletion go-sdk/integration-test/eth_e2e/resources/besu/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
data-path = "/opt/besu/data"
genesis-file = "/data/l1-node-config/genesis.json"
network-id = 1337
logging = "INFO"
logging = "DEBUG"

# RPC
rpc-http-enabled = true
Expand Down
3 changes: 2 additions & 1 deletion go-sdk/integration-test/eth_e2e/resources/besu/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"blockperiodseconds": 1,
"epochlength": 30000,
"requesttimeoutseconds": 4
}
},
"contractSizeLimit": 2147483647
},
"nonce": "0x0",
"timestamp": "0x58ee40ba",
Expand Down
6 changes: 4 additions & 2 deletions go-sdk/integration-test/smt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"testing"

"github.com/hyperledger-labs/zeto/go-sdk/integration-test/common"
"github.com/hyperledger-labs/zeto/go-sdk/pkg/crypto"
"github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/node"
"github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/smt"
"github.com/iden3/go-iden3-crypto/babyjub"
Expand Down Expand Up @@ -72,15 +73,16 @@ func testConcurrentInsertion(t *testing.T, alice *babyjub.PublicKey, values []in
assert.NoError(t, err)
}()

hasher := crypto.NewPoseidonHasher()
mt, err := smt.NewMerkleTree(db, common.MAX_HEIGHT)
assert.NoError(t, err)
done := make(chan bool, len(values))

for i, v := range values {
go func(i, v int) {
salt, _ := new(big.Int).SetString(salts[i], 16)
utxo := node.NewFungible(big.NewInt(int64(v)), alice, salt)
n, err := node.NewLeafNode(utxo)
utxo := node.NewFungible(big.NewInt(int64(v)), alice, salt, hasher)
n, err := node.NewLeafNode(utxo, nil)
assert.NoError(t, err)
err = mt.AddLeaf(n)
assert.NoError(t, err)
Expand Down
62 changes: 62 additions & 0 deletions go-sdk/internal/crypto/hash/keccak256.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright © 2025 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package hash

import (
"encoding/json"
"math/big"
"strconv"

"github.com/hyperledger/firefly-signer/pkg/abi"
"golang.org/x/crypto/sha3"
)

type Keccak256Hasher struct{}

func (k *Keccak256Hasher) Hash(inputs []*big.Int) (*big.Int, error) {
paramTypes := abi.ParameterArray{}
paramValues := map[string]any{}
for i, input := range inputs {
paramTypes = append(paramTypes, &abi.Parameter{
Type: "uint256",
Name: strconv.Itoa(i),
})
paramValues[strconv.Itoa(i)] = "0x" + input.Text(16)
}

jsonData, err := json.Marshal(paramValues)
if err != nil {
return nil, err
}

encoded, err := paramTypes.EncodeABIDataJSON(jsonData)
if err != nil {
return nil, err
}
hash := sha3.NewLegacyKeccak256()
hash.Write(encoded)
h32 := make([]byte, 32)
h := hash.Sum(h32)
_hash := new(big.Int).SetBytes(h)
return _hash, nil
}

func (k *Keccak256Hasher) CheckInRange(a *big.Int) bool {
// The range is [0, 2^256 - 1] for Keccak256 inputs
max := new(big.Int).Lsh(big.NewInt(1), 256)
return a.Cmp(big.NewInt(0)) >= 0 && a.Cmp(max) < 0
}
Loading
Loading