Skip to content

Commit

Permalink
Merge pull request #35 from hyperledger-labs/naming
Browse files Browse the repository at this point in the history
Rename circuit inputs to have consistent naming conventions
  • Loading branch information
Chengxuan authored Aug 13, 2024
2 parents 6544a70 + f19c3b9 commit a7b9e39
Show file tree
Hide file tree
Showing 55 changed files with 535 additions and 186 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
env:
PROVING_KEYS_ROOT: ${{ runner.temp }}/zeto-artifacts
CIRCUITS_ROOT: ${{ github.workspace }}/zkp/js/lib
working-directory: zkp/golang
working-directory: go-sdk
run: |
make e2e
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/golang.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ jobs:
go-version: 1.22

- name: Build and Test
run: cd zkp/golang && make
working-directory: go-sdk
run: make

- uses: codecov/codecov-action@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ The project does not include an implementation of a notary based token transfer
There are 4 sub-projects. Navigate to each sub-project to run the tests and learn how to use each library:

- [ZKP circuits](./zkp/circuits/): ZKP circuits written in circom to support the Zeto privacy patterns
- [golang library for proof generation](./zkp/golang/): test cases written in golang
- [golang library for proof generation](./go-sdk/): test cases written in golang
- [javascript library for proof generation](./zkp/js/): test cases written in javascript
- [Solidity library for onchain proof verification](./solidity/): Sample Solidity contracts for all the ZKP based Zeto privacy patterns
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions zkp/golang/go.mod → go-sdk/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/hyperledger-labs/zeto
module github.com/hyperledger-labs/zeto/go-sdk

go 1.22.0

Expand Down Expand Up @@ -47,7 +47,7 @@ require (
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.26.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/sys v0.24.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/postgres v1.5.9
gorm.io/driver/sqlite v1.5.6
Expand Down
14 changes: 2 additions & 12 deletions zkp/golang/go.sum → go-sdk/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,19 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/x-cray/logrus-prefixed-formatter v0.5.2 h1:00txxvfBM9muc0jiLIEAkAcIMJzfthRT6usrui8uGmg=
github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
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.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk=
golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU=
golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import (
"testing"
"time"

"github.com/hyperledger-labs/zeto/internal/testutils"
keyscore "github.com/hyperledger-labs/zeto/pkg/key-manager/core"
"github.com/hyperledger-labs/zeto/pkg/key-manager/key"
"github.com/hyperledger-labs/zeto/pkg/sparse-merkle-tree/core"
"github.com/hyperledger-labs/zeto/pkg/sparse-merkle-tree/node"
"github.com/hyperledger-labs/zeto/pkg/sparse-merkle-tree/smt"
"github.com/hyperledger-labs/zeto/pkg/sparse-merkle-tree/storage"
"github.com/hyperledger-labs/zeto/pkg/sparse-merkle-tree/utxo"
"github.com/hyperledger-labs/zeto/go-sdk/internal/testutils"
keyscore "github.com/hyperledger-labs/zeto/go-sdk/pkg/key-manager/core"
"github.com/hyperledger-labs/zeto/go-sdk/pkg/key-manager/key"
"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"
"github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/storage"
"github.com/hyperledger-labs/zeto/go-sdk/pkg/utxo"
"github.com/hyperledger/firefly-signer/pkg/keystorev3"
"github.com/hyperledger/firefly-signer/pkg/secp256k1"
"github.com/iden3/go-iden3-crypto/babyjub"
Expand Down Expand Up @@ -128,23 +128,23 @@ func TestZeto_1_SuccessfulProving(t *testing.T) {
inputValues := []*big.Int{big.NewInt(30), big.NewInt(40)}
outputValues := []*big.Int{big.NewInt(32), big.NewInt(38)}

salt1 := testutils.NewSalt()
salt1 := utxo.NewSalt()
input1, _ := poseidon.Hash([]*big.Int{inputValues[0], salt1, sender.PublicKey.X, sender.PublicKey.Y})
salt2 := testutils.NewSalt()
salt2 := utxo.NewSalt()
input2, _ := poseidon.Hash([]*big.Int{inputValues[1], salt2, sender.PublicKey.X, sender.PublicKey.Y})
inputCommitments := []*big.Int{input1, input2}

salt3 := testutils.NewSalt()
salt3 := utxo.NewSalt()
output1, _ := poseidon.Hash([]*big.Int{outputValues[0], salt3, receiver.PublicKey.X, receiver.PublicKey.Y})
salt4 := testutils.NewSalt()
salt4 := utxo.NewSalt()
output2, _ := poseidon.Hash([]*big.Int{outputValues[1], salt4, sender.PublicKey.X, sender.PublicKey.Y})
outputCommitments := []*big.Int{output1, output2}

witnessInputs := map[string]interface{}{
"inputCommitments": inputCommitments,
"inputValues": inputValues,
"inputSalts": []*big.Int{salt1, salt2},
"senderPrivateKey": sender.PrivateKeyForZkp,
"inputOwnerPrivateKey": sender.PrivateKeyForZkp,
"outputCommitments": outputCommitments,
"outputValues": outputValues,
"outputSalts": []*big.Int{salt3, salt4},
Expand Down Expand Up @@ -189,25 +189,25 @@ func TestZeto_2_SuccessfulProving(t *testing.T) {
inputValues := []*big.Int{big.NewInt(30), big.NewInt(40)}
outputValues := []*big.Int{big.NewInt(32), big.NewInt(38)}

salt1 := testutils.NewSalt()
salt1 := utxo.NewSalt()
input1, _ := poseidon.Hash([]*big.Int{inputValues[0], salt1, sender.PublicKey.X, sender.PublicKey.Y})
salt2 := testutils.NewSalt()
salt2 := utxo.NewSalt()
input2, _ := poseidon.Hash([]*big.Int{inputValues[1], salt2, sender.PublicKey.X, sender.PublicKey.Y})
inputCommitments := []*big.Int{input1, input2}

salt3 := testutils.NewSalt()
salt3 := utxo.NewSalt()
output1, _ := poseidon.Hash([]*big.Int{outputValues[0], salt3, receiver.PublicKey.X, receiver.PublicKey.Y})
salt4 := testutils.NewSalt()
salt4 := utxo.NewSalt()
output2, _ := poseidon.Hash([]*big.Int{outputValues[1], salt4, sender.PublicKey.X, sender.PublicKey.Y})
outputCommitments := []*big.Int{output1, output2}

encryptionNonce := testutils.NewSalt()
encryptionNonce := utxo.NewSalt()

witnessInputs := map[string]interface{}{
"inputCommitments": inputCommitments,
"inputValues": inputValues,
"inputSalts": []*big.Int{salt1, salt2},
"senderPrivateKey": sender.PrivateKeyForZkp,
"inputOwnerPrivateKey": sender.PrivateKeyForZkp,
"outputCommitments": outputCommitments,
"outputValues": outputValues,
"outputSalts": []*big.Int{salt3, salt4},
Expand Down Expand Up @@ -241,9 +241,9 @@ func TestZeto_3_SuccessfulProving(t *testing.T) {
inputValues := []*big.Int{big.NewInt(30), big.NewInt(40)}
outputValues := []*big.Int{big.NewInt(32), big.NewInt(38)}

salt1 := testutils.NewSalt()
salt1 := utxo.NewSalt()
input1, _ := poseidon.Hash([]*big.Int{inputValues[0], salt1, sender.PublicKey.X, sender.PublicKey.Y})
salt2 := testutils.NewSalt()
salt2 := utxo.NewSalt()
input2, _ := poseidon.Hash([]*big.Int{inputValues[1], salt2, sender.PublicKey.X, sender.PublicKey.Y})
inputCommitments := []*big.Int{input1, input2}

Expand All @@ -253,12 +253,12 @@ func TestZeto_3_SuccessfulProving(t *testing.T) {

mt, err := smt.NewMerkleTree(storage.NewMemoryStorage(), MAX_HEIGHT)
assert.NoError(t, err)
utxo1 := utxo.NewFungible(inputValues[0], sender.PublicKey, salt1)
utxo1 := node.NewFungible(inputValues[0], sender.PublicKey, salt1)
n1, err := node.NewLeafNode(utxo1)
assert.NoError(t, err)
err = mt.AddLeaf(n1)
assert.NoError(t, err)
utxo2 := utxo.NewFungible(inputValues[1], sender.PublicKey, salt2)
utxo2 := node.NewFungible(inputValues[1], sender.PublicKey, salt2)
n2, err := node.NewLeafNode(utxo2)
assert.NoError(t, err)
err = mt.AddLeaf(n2)
Expand All @@ -272,9 +272,9 @@ func TestZeto_3_SuccessfulProving(t *testing.T) {
circomProof2, err := proof2.ToCircomVerifierProof(input2, input2, mt.Root(), MAX_HEIGHT)
assert.NoError(t, err)

salt3 := testutils.NewSalt()
salt3 := utxo.NewSalt()
output1, _ := poseidon.Hash([]*big.Int{outputValues[0], salt3, receiver.PublicKey.X, receiver.PublicKey.Y})
salt4 := testutils.NewSalt()
salt4 := utxo.NewSalt()
output2, _ := poseidon.Hash([]*big.Int{outputValues[1], salt4, sender.PublicKey.X, sender.PublicKey.Y})
outputCommitments := []*big.Int{output1, output2}

Expand Down Expand Up @@ -327,9 +327,9 @@ func TestZeto_4_SuccessfulProving(t *testing.T) {
inputValues := []*big.Int{big.NewInt(30), big.NewInt(40)}
outputValues := []*big.Int{big.NewInt(32), big.NewInt(38)}

salt1 := testutils.NewSalt()
salt1 := utxo.NewSalt()
input1, _ := poseidon.Hash([]*big.Int{inputValues[0], salt1, sender.PublicKey.X, sender.PublicKey.Y})
salt2 := testutils.NewSalt()
salt2 := utxo.NewSalt()
input2, _ := poseidon.Hash([]*big.Int{inputValues[1], salt2, sender.PublicKey.X, sender.PublicKey.Y})
inputCommitments := []*big.Int{input1, input2}

Expand All @@ -339,12 +339,12 @@ func TestZeto_4_SuccessfulProving(t *testing.T) {

mt, err := smt.NewMerkleTree(storage.NewMemoryStorage(), MAX_HEIGHT)
assert.NoError(t, err)
utxo1 := utxo.NewFungible(inputValues[0], sender.PublicKey, salt1)
utxo1 := node.NewFungible(inputValues[0], sender.PublicKey, salt1)
n1, err := node.NewLeafNode(utxo1)
assert.NoError(t, err)
err = mt.AddLeaf(n1)
assert.NoError(t, err)
utxo2 := utxo.NewFungible(inputValues[1], sender.PublicKey, salt2)
utxo2 := node.NewFungible(inputValues[1], sender.PublicKey, salt2)
n2, err := node.NewLeafNode(utxo2)
assert.NoError(t, err)
err = mt.AddLeaf(n2)
Expand All @@ -358,13 +358,13 @@ func TestZeto_4_SuccessfulProving(t *testing.T) {
circomProof2, err := proof2.ToCircomVerifierProof(input2, input2, mt.Root(), MAX_HEIGHT)
assert.NoError(t, err)

salt3 := testutils.NewSalt()
salt3 := utxo.NewSalt()
output1, _ := poseidon.Hash([]*big.Int{outputValues[0], salt3, receiver.PublicKey.X, receiver.PublicKey.Y})
salt4 := testutils.NewSalt()
salt4 := utxo.NewSalt()
output2, _ := poseidon.Hash([]*big.Int{outputValues[1], salt4, sender.PublicKey.X, sender.PublicKey.Y})
outputCommitments := []*big.Int{output1, output2}

encryptionNonce := testutils.NewSalt()
encryptionNonce := utxo.NewSalt()

proof1Siblings := make([]*big.Int, len(circomProof1.Siblings)-1)
for i, s := range circomProof1.Siblings[0 : len(circomProof1.Siblings)-1] {
Expand Down Expand Up @@ -417,11 +417,11 @@ func TestZeto_5_SuccessfulProving(t *testing.T) {
tokenUri, err := utxo.HashTokenUri("https://example.com/token/1001")
assert.NoError(t, err)

salt1 := testutils.NewSalt()
salt1 := utxo.NewSalt()
input1, err := poseidon.Hash([]*big.Int{tokenId, tokenUri, salt1, sender.PublicKey.X, sender.PublicKey.Y})
assert.NoError(t, err)

salt3 := testutils.NewSalt()
salt3 := utxo.NewSalt()
output1, err := poseidon.Hash([]*big.Int{tokenId, tokenUri, salt3, receiver.PublicKey.X, receiver.PublicKey.Y})
assert.NoError(t, err)

Expand All @@ -430,7 +430,7 @@ func TestZeto_5_SuccessfulProving(t *testing.T) {
"tokenUris": []*big.Int{tokenUri},
"inputCommitments": []*big.Int{input1},
"inputSalts": []*big.Int{salt1},
"senderPrivateKey": sender.PrivateKeyBigInt,
"inputOwnerPrivateKey": sender.PrivateKeyBigInt,
"outputCommitments": []*big.Int{output1},
"outputSalts": []*big.Int{salt3},
"outputOwnerPublicKeys": [][]*big.Int{{receiver.PublicKey.X, receiver.PublicKey.Y}},
Expand Down Expand Up @@ -472,18 +472,19 @@ func TestZeto_6_SuccessfulProving(t *testing.T) {
receiver := testutils.NewKeypair()

tokenId := big.NewInt(1001)
tokenUri, err := utxo.HashTokenUri("https://example.com/token/1001")
uriString := "https://example.com/token/1001"
tokenUri, err := utxo.HashTokenUri(uriString)
assert.NoError(t, err)

salt1 := testutils.NewSalt()
salt1 := utxo.NewSalt()
input1, err := poseidon.Hash([]*big.Int{tokenId, tokenUri, salt1, sender.PublicKey.X, sender.PublicKey.Y})
assert.NoError(t, err)

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

mt, err := smt.NewMerkleTree(storage.NewMemoryStorage(), MAX_HEIGHT)
assert.NoError(t, err)
utxo1 := utxo.NewNonFungible(tokenId, tokenUri, sender.PublicKey, salt1)
utxo1 := node.NewNonFungible(tokenId, uriString, sender.PublicKey, salt1)
n1, err := node.NewLeafNode(utxo1)
assert.NoError(t, err)
err = mt.AddLeaf(n1)
Expand All @@ -497,7 +498,7 @@ func TestZeto_6_SuccessfulProving(t *testing.T) {
proof1Siblings[i] = s.BigInt()
}

salt3 := testutils.NewSalt()
salt3 := utxo.NewSalt()
output1, err := poseidon.Hash([]*big.Int{tokenId, tokenUri, salt3, receiver.PublicKey.X, receiver.PublicKey.Y})
assert.NoError(t, err)

Expand Down Expand Up @@ -576,7 +577,7 @@ func testConcurrentInsertion(t *testing.T, alice *babyjub.PublicKey, values []in
for i, v := range values {
go func(i, v int) {
salt, _ := new(big.Int).SetString(salts[i], 16)
utxo := utxo.NewFungible(big.NewInt(int64(v)), alice, salt)
utxo := node.NewFungible(big.NewInt(int64(v)), alice, salt)
n, err := node.NewLeafNode(utxo)
assert.NoError(t, err)
err = mt.AddLeaf(n)
Expand Down Expand Up @@ -623,12 +624,12 @@ func TestSqliteStorage(t *testing.T) {
assert.NoError(t, err)

tokenId := big.NewInt(1001)
tokenUri, err := utxo.HashTokenUri("https://example.com/token/1001")
uriString := "https://example.com/token/1001"
assert.NoError(t, err)
sender := testutils.NewKeypair()
salt1 := testutils.NewSalt()
salt1 := utxo.NewSalt()

utxo1 := utxo.NewNonFungible(tokenId, tokenUri, sender.PublicKey, salt1)
utxo1 := node.NewNonFungible(tokenId, uriString, sender.PublicKey, salt1)
n1, err := node.NewLeafNode(utxo1)
assert.NoError(t, err)
err = mt.AddLeaf(n1)
Expand Down Expand Up @@ -668,12 +669,12 @@ func TestPostgresStorage(t *testing.T) {
assert.NoError(t, err)

tokenId := big.NewInt(1001)
tokenUri, err := utxo.HashTokenUri("https://example.com/token/1001")
tokenUri := "https://example.com/token/1001"
assert.NoError(t, err)
sender := testutils.NewKeypair()
salt1 := testutils.NewSalt()
salt1 := utxo.NewSalt()

utxo1 := utxo.NewNonFungible(tokenId, tokenUri, sender.PublicKey, salt1)
utxo1 := node.NewNonFungible(tokenId, tokenUri, sender.PublicKey, salt1)
n1, err := node.NewLeafNode(utxo1)
assert.NoError(t, err)
err = mt.AddLeaf(n1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package key

import (
"github.com/hyperledger-labs/zeto/pkg/key-manager/core"
"github.com/hyperledger-labs/zeto/go-sdk/pkg/key-manager/core"
"github.com/iden3/go-iden3-crypto/babyjub"
)

Expand Down
Loading

0 comments on commit a7b9e39

Please sign in to comment.