diff --git a/go-sdk/go.mod b/go-sdk/go.mod index d6b98504..0fda33ff 100644 --- a/go-sdk/go.mod +++ b/go-sdk/go.mod @@ -3,8 +3,8 @@ 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 @@ -12,24 +12,24 @@ require ( 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 @@ -44,14 +44,13 @@ 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 ) @@ -59,17 +58,16 @@ 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 ) diff --git a/go-sdk/go.sum b/go-sdk/go.sum index 3098767f..3b0985dc 100644 --- a/go-sdk/go.sum +++ b/go-sdk/go.sum @@ -2,18 +2,16 @@ github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= -github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA= -github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8= -github.com/VictoriaMetrics/fastcache v1.12.2 h1:N0y9ASrJ0F6h0QaC3o6uJb3NIZ9VKLjCM7NQbSmF7WI= -github.com/VictoriaMetrics/fastcache v1.12.2/go.mod h1:AmC+Nzz1+3G2eCPapF6UcsnkThDcMsQicp4xDukwJYI= +github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20251208031133-be43a854e4be h1:1LtMLkGIqE5IQZ7Vdh4zv8A6LECInKF86/fTVxKxYLE= +github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20251208031133-be43a854e4be/go.mod h1:ioLG6R+5bUSO1oeGSDxOV3FADARuMoytZCSX6MEMQkI= +github.com/VictoriaMetrics/fastcache v1.13.0 h1:AW4mheMR5Vd9FkAPUv+NH6Nhw+fmbTMGMsNAoA/+4G0= +github.com/VictoriaMetrics/fastcache v1.13.0/go.mod h1:hHXhl4DA2fTL2HTZDJFXWgW0LNjo6B+4aj2Wmng3TjU= github.com/aidarkhanov/nanoid v1.0.8 h1:yxyJkgsEDFXP7+97vc6JevMcjyb03Zw+/9fqhlVXBXA= github.com/aidarkhanov/nanoid v1.0.8/go.mod h1:vadfZHT+m4uDhttg0yY4wW3GKtl2T6i4d2Age+45pYk= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/bits-and-blooms/bitset v1.20.0 h1:2F+rfL86jE2d/bmw7OhqUg2Sj/1rURkBn3MdfoPyRVU= -github.com/bits-and-blooms/bitset v1.20.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= -github.com/bits-and-blooms/bitset v1.24.0 h1:H4x4TuulnokZKvHLfzVRTHJfFfnHEeSYJizujEZvmAM= -github.com/bits-and-blooms/bitset v1.24.0/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/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= @@ -36,14 +34,10 @@ github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwP github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ= -github.com/consensys/gnark-crypto v0.18.0 h1:vIye/FqI50VeAr0B3dx+YjeIvmc3LWz4yEfbWBpTUf0= -github.com/consensys/gnark-crypto v0.18.0/go.mod h1:L3mXGFTe1ZN+RSJ+CLjUt9x7PNdx8ubaYfDROyp2Z8c= -github.com/consensys/gnark-crypto v0.19.0 h1:zXCqeY2txSaMl6G5wFpZzMWJU9HPNh8qxPnYJ1BL9vA= -github.com/consensys/gnark-crypto v0.19.0/go.mod h1:rT23F0XSZqE0mUA0+pRtnL56IbPxs6gp4CeRsBk4XS0= +github.com/consensys/gnark-crypto v0.19.2 h1:qrEAIXq3T4egxqiliFFoNrepkIWVEeIYwt3UL0fvS80= +github.com/consensys/gnark-crypto v0.19.2/go.mod h1:rT23F0XSZqE0mUA0+pRtnL56IbPxs6gp4CeRsBk4XS0= github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc= github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/crate-crypto/go-eth-kzg v1.3.0 h1:05GrhASN9kDAidaFJOda6A4BEvgvuXbazXg/0E3OOdI= -github.com/crate-crypto/go-eth-kzg v1.3.0/go.mod h1:J9/u5sWfznSObptgfa92Jq8rTswn6ahQWEuiLHOjCUI= github.com/crate-crypto/go-eth-kzg v1.4.0 h1:WzDGjHk4gFg6YzV0rJOAsTK4z3Qkz5jd4RE3DAvPFkg= github.com/crate-crypto/go-eth-kzg v1.4.0/go.mod h1:J9/u5sWfznSObptgfa92Jq8rTswn6ahQWEuiLHOjCUI= github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a h1:W8mUrRp6NOVl3J+MYp5kPMoUZPp7aOYHtaua31lwRHg= @@ -56,14 +50,10 @@ github.com/dchest/blake512 v1.0.0 h1:oDFEQFIqFSeuA34xLtXZ/rWxCXdSjirjzPhey5EUvmA github.com/dchest/blake512 v1.0.0/go.mod h1:FV1x7xPPLWukZlpDpWQ88rF/SFwZ5qbskrzhLMB92JI= github.com/dchest/siphash v1.2.3 h1:QXwFc8cFOR2dSa/gE6o/HokBMWtLUaNDVd+22aKHeEA= github.com/dchest/siphash v1.2.3/go.mod h1:0NvQU092bT0ipiFN++/rXm69QG9tVxLAlQHIXMPAkHc= -github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80NsVHagjM= -github.com/deckarep/golang-set/v2 v2.6.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= github.com/deckarep/golang-set/v2 v2.8.0 h1:swm0rlPCmdWn9mESxKOjWk8hXSqoxOp+ZlfuyaAdFlQ= github.com/deckarep/golang-set/v2 v2.8.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= -github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= -github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= +github.com/decred/dcrd/crypto/blake256 v1.1.0 h1:zPMNGQCm0g4QTY27fOCorQW7EryeQ/U0x++OzVrdms8= +github.com/decred/dcrd/crypto/blake256 v1.1.0/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40= github.com/deepmap/oapi-codegen v1.6.0 h1:w/d1ntwh91XI0b/8ja7+u5SvA4IFfM0UNNLmiDR1gg0= @@ -72,82 +62,81 @@ github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4 github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/emicklei/dot v1.6.2 h1:08GN+DD79cy/tzN6uLCT84+2Wk9u+wvqP+Hkx/dIR8A= github.com/emicklei/dot v1.6.2/go.mod h1:DeV7GvQtIw4h2u73RKBkkFdvVAz0D9fzeJrgPW6gy/s= -github.com/ethereum/c-kzg-4844/v2 v2.1.0 h1:gQropX9YFBhl3g4HYhwE70zq3IHFRgbbNPw0Shwzf5w= -github.com/ethereum/c-kzg-4844/v2 v2.1.0/go.mod h1:TC48kOKjJKPbN7C++qIgt0TJzZ70QznYR7Ob+WXl57E= -github.com/ethereum/c-kzg-4844/v2 v2.1.2 h1:TsHMflcX0Wjjdwvhtg39HOozknAlQKY9PnG5Zf3gdD4= -github.com/ethereum/c-kzg-4844/v2 v2.1.2/go.mod h1:u59hRTTah4Co6i9fDWtiCjTrblJv0UwsqZKCc0GfgUs= -github.com/ethereum/go-ethereum v1.16.3 h1:nDoBSrmsrPbrDIVLTkDQCy1U9KdHN+F2PzvMbDoS42Q= -github.com/ethereum/go-ethereum v1.16.3/go.mod h1:Lrsc6bt9Gm9RyvhfFK53vboCia8kpF9nv+2Ukntnl+8= +github.com/ethereum/c-kzg-4844/v2 v2.1.5 h1:aVtoLK5xwJ6c5RiqO8g8ptJ5KU+2Hdquf6G3aXiHh5s= +github.com/ethereum/c-kzg-4844/v2 v2.1.5/go.mod h1:u59hRTTah4Co6i9fDWtiCjTrblJv0UwsqZKCc0GfgUs= +github.com/ethereum/go-bigmodexpfix v0.0.0-20250911101455-f9e208c548ab h1:rvv6MJhy07IMfEKuARQ9TKojGqLVNxQajaXEp/BoqSk= +github.com/ethereum/go-bigmodexpfix v0.0.0-20250911101455-f9e208c548ab/go.mod h1:IuLm4IsPipXKF7CW5Lzf68PIbZ5yl7FFd74l/E0o9A8= +github.com/ethereum/go-ethereum v1.16.7 h1:qeM4TvbrWK0UC0tgkZ7NiRsmBGwsjqc64BHo20U59UQ= +github.com/ethereum/go-ethereum v1.16.7/go.mod h1:Fs6QebQbavneQTYcA39PEKv2+zIjX7rPUZ14DER46wk= github.com/ethereum/go-verkle v0.2.2 h1:I2W0WjnrFUIzzVPwm8ykY+7pL2d4VhlsePn4j7cnFk8= github.com/ethereum/go-verkle v0.2.2/go.mod h1:M3b90YRnzqKyyzBEWJGqj8Qff4IDeXnzFw0P9bFw3uk= github.com/ferranbt/fastssz v0.1.4 h1:OCDB+dYDEQDvAgtAGnTSidK1Pe2tW3nFV40XyMkTeDY= github.com/ferranbt/fastssz v0.1.4/go.mod h1:Ea3+oeoRGGLGm5shYAeDgu6PGUlcvQhE2fILyD9+tGg= -github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= -github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqGNY4FhTFhk+o9oFHGINQ/+vhlm8HFzi6znCI= github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= +github.com/getkin/kin-openapi v0.131.0 h1:NO2UeHnFKRYhZ8wg6Nyh5Cq7dHk4suQQr72a4pMrDxE= +github.com/getkin/kin-openapi v0.131.0/go.mod h1:3OlG51PCYNsPByuiMB0t4fjnNlIDnaEDsjiKUV8nL58= github.com/getsentry/sentry-go v0.27.0 h1:Pv98CIbtB3LkMWmXi4Joa5OOcwbmnX88sF5qbK3r3Ps= github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= -github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= +github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= +github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= +github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= +github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E= github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI= github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= -github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk= -github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs= +github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= -github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= -github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/graph-gophers/graphql-go v1.3.0 h1:Eb9x/q6MFpCLz7jBCiP/WTxjSDrYLR1QY41SORZyNJ0= github.com/graph-gophers/graphql-go v1.3.0/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc= github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE= github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0= -github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 h1:X4egAf/gcS1zATw6wn4Ej8vjuVGxeHdan+bRb2ebyv4= -github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4/go.mod h1:5GuXa7vkL8u9FkFuWdVvfR5ix8hRB7DbOAaYULamFpc= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/holiman/billy v0.0.0-20250707135307-f2f9b9aae7db h1:IZUYC/xb3giYwBLMnr8d0TGTzPKFGNTCGgGLoyeX330= +github.com/holiman/billy v0.0.0-20250707135307-f2f9b9aae7db/go.mod h1:xTEYN9KCHxuYHs+NmrmzFcnvHMzLLNiGFafCb1n3Mfg= github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= github.com/holiman/uint256 v1.3.2 h1:a9EgMPSC1AAaj1SZL5zIQD3WbwTuHrMGOerLjGmM/TA= github.com/holiman/uint256 v1.3.2/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc= github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= -github.com/hyperledger/firefly-common v1.4.6 h1:qqXoSaRml3WjUnWcWxrrXs5AIOWa+UcMXLCF8yEa4Pk= -github.com/hyperledger/firefly-common v1.4.6/go.mod h1:jkErZdQmC9fsAJZQO427tURdwB9iiW+NMUZSqS3eBIE= -github.com/hyperledger/firefly-signer v1.1.13 h1:eiHjc6HPRG8AzXUCUgm51qqX1I9BokiuiiqJ89XwK4M= -github.com/hyperledger/firefly-signer v1.1.13/go.mod h1:pK6kivzBFSue3zpJSQpH67VasnLLbwBJOBUNv0zHbRA= +github.com/hyperledger/firefly-common v1.5.9 h1:Z1+SuKNYJ8hPKQ5CvcsMg6r/E4RyW6wb08nGwtcc8Ww= +github.com/hyperledger/firefly-common v1.5.9/go.mod h1:1Xawm5PUhxT7k+CL/Kr3i1LE3cTTzoQwZMLimvlW8rs= +github.com/hyperledger/firefly-signer v1.1.22 h1:j0D9rmoJFCrtYyko3M4Wt6JQ2GNQtWL7WLSS8xKoW3g= +github.com/hyperledger/firefly-signer v1.1.22/go.mod h1:hDYvfn8g0cEw0Tz1H7nmblj25D8ImytxIIqh7MMoiog= github.com/iden3/go-iden3-crypto v0.0.17 h1:NdkceRLJo/pI4UpcjVah4lN/a3yzxRUGXqxbWcYh9mY= github.com/iden3/go-iden3-crypto v0.0.17/go.mod h1:dLpM4vEPJ3nDHzhWFXDjzkn1qHoBeOT/3UEhXsEsP3E= -github.com/iden3/go-rapidsnark/prover v0.0.10 h1:NvOfRPpex/k646UsqOcUy7a7uVl17t4ok9kWvpQg4+k= -github.com/iden3/go-rapidsnark/prover v0.0.10/go.mod h1:wgDsmKOGCuWGtgVtuW9ARWNguNr4NJAIyg2G7+uTax0= -github.com/iden3/go-rapidsnark/prover v0.0.13 h1:UJExuem56pawmsE03OdKmOPc/y8nPmh6+GJ54dAyzZk= -github.com/iden3/go-rapidsnark/prover v0.0.13/go.mod h1:mUNLeDXYOW2igiPuhHZHD7kzSp/GjHSWND03aYyECvQ= -github.com/iden3/go-rapidsnark/types v0.0.2 h1:CjJSrlbWchHzuMRdxSYrEh7n/akP+Z2PLNbwT5yBmQY= -github.com/iden3/go-rapidsnark/types v0.0.2/go.mod h1:ApgcaUxKIgSRA6fAeFxK7p+lgXXfG4oA2HN5DhFlfF4= +github.com/iden3/go-rapidsnark/prover v0.0.15 h1:es0jUD6GR7jZS6MO92Tjt90edpSWeTsdsm/tah4hLWs= +github.com/iden3/go-rapidsnark/prover v0.0.15/go.mod h1:mUNLeDXYOW2igiPuhHZHD7kzSp/GjHSWND03aYyECvQ= github.com/iden3/go-rapidsnark/types v0.0.3 h1:f0s1Qdut1qHe1O67+m+xUVRBPwSXnq5j0xSrBi0jqM4= github.com/iden3/go-rapidsnark/types v0.0.3/go.mod h1:ApgcaUxKIgSRA6fAeFxK7p+lgXXfG4oA2HN5DhFlfF4= -github.com/iden3/go-rapidsnark/verifier v0.0.5 h1:J7y0ovrEjDQoWtZmlrp4tgGng1A9faMeYsQH4igAEqA= -github.com/iden3/go-rapidsnark/verifier v0.0.5/go.mod h1:KgL3Yr9NehlFDI4EIWVLE3UDUi8ulyjbp7HcXSBfiGI= github.com/iden3/go-rapidsnark/witness/v2 v2.0.0 h1:mkY6VDfwKVJc83QGKmwVXY2LYepidPrFAxskrjr8UCs= github.com/iden3/go-rapidsnark/witness/v2 v2.0.0/go.mod h1:3JRjqUfW1hgI9hzLDO0v8z/DUkR0ZUehhYLlnIfRxnA= -github.com/iden3/go-rapidsnark/witness/wasmer v0.0.0-20230524142950-0986cf057d4e h1:lqrevdLsG1k8ieaxgUQccf3unf73m3zmkHJ3oIdld90= -github.com/iden3/go-rapidsnark/witness/wasmer v0.0.0-20230524142950-0986cf057d4e/go.mod h1:WUtPVKXrhfZHJXavwId2+8J/fKMHQ92N0MZDxt8sfEA= -github.com/iden3/go-rapidsnark/witness/wasmer v0.0.0-20250114164021-779c4f7dbadd h1:lVQMc5Y9Ab1ycVUXAleIrSr30/Z3PqetRKJ/4DDHK3M= -github.com/iden3/go-rapidsnark/witness/wasmer v0.0.0-20250114164021-779c4f7dbadd/go.mod h1:WUtPVKXrhfZHJXavwId2+8J/fKMHQ92N0MZDxt8sfEA= +github.com/iden3/go-rapidsnark/witness/wasmer v0.0.0-20251113130218-15cc9f587b90 h1:FaQmmZ55ZXQbkZGwkP6OTdQFQelW01DcQC5PAhPG6Tc= +github.com/iden3/go-rapidsnark/witness/wasmer v0.0.0-20251113130218-15cc9f587b90/go.mod h1:WUtPVKXrhfZHJXavwId2+8J/fKMHQ92N0MZDxt8sfEA= github.com/iden3/wasmer-go v0.0.1 h1:TZKh8Se8B/73PvWrcu+FTU9L1k5XYAmtFbioj7l0Uog= github.com/iden3/wasmer-go v0.0.1/go.mod h1:ZnZBAO012M7o+Q1INXLRIxKQgEcH2FuwL0Iga8A4ufg= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/influxdata/influxdb-client-go/v2 v2.4.0 h1:HGBfZYStlx3Kqvsv1h2pJixbCl/jhnFtxpKFAv9Tu5k= github.com/influxdata/influxdb-client-go/v2 v2.4.0/go.mod h1:vLNHdxTJkIf2mSLvGrpj8TCcISApPoXkaxP8g9uRlW8= github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c h1:qSHzRbhzK8RdXOsAdfDgO49TtqC1oZ+acxPrkfTxcCs= @@ -168,6 +157,8 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/klauspost/compress v1.16.0 h1:iULayQNOReoYUe+1qtKOqw9CwJv3aNQu8ivo7lw1HU4= github.com/klauspost/compress v1.16.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= @@ -180,14 +171,16 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/leanovate/gopter v0.2.11 h1:vRjThO1EKPb/1NsDXuDrzldR28RLkBflWYcU9CvzWu4= github.com/leanovate/gopter v0.2.11/go.mod h1:aK3tzZP/C+p1m3SPRE4SYZFGP7jjkuSI4f7Xvpt0S9c= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= -github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/mattn/go-sqlite3 v1.14.32 h1:JD12Ag3oLy1zQA+BNn74xRgaBbdhbNIDYvQUEuuErjs= github.com/mattn/go-sqlite3 v1.14.32/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= @@ -201,8 +194,14 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= +github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 h1:G7ERwszslrBzRxj//JalHPu/3yz+De2J+4aLtSRlHiY= +github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037/go.mod h1:2bpvgLBZEtENV5scfDFEtB/5+1M4hkQhDQrccEJ/qGw= +github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 h1:bQx3WeLcUWy+RletIKwUIt4x3t8n2SxavmoclizMb8c= +github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90/go.mod h1:y5+oSEHCPT/DGrS++Wc/479ERge0zTFxaF8PbGKcg2o= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= @@ -211,6 +210,11 @@ github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw= github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= +github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI= +github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s= +github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw= github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 h1:oYW+YCJ1pachXTQmzR3rNLYGGz4g/UgFcjb28p/viDM= github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= github.com/pion/dtls/v2 v2.2.7 h1:cSUBsETxepsCSFSxC3mc/aDo14qQLMSL+O6IjG28yV8= @@ -240,39 +244,47 @@ github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= -github.com/rs/cors v1.10.1 h1:L0uuZVXIKlI1SShY2nhFfo44TYvDPQ1w4oFkUJNfhyo= -github.com/rs/cors v1.10.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= +github.com/rs/cors v1.11.1 h1:eU3gRzXLRK57F5rKMGMZURNdIG4EoAmX8k94r9wXWHA= +github.com/rs/cors v1.11.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= +github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= +github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= +github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4= github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY= -github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= -github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= +github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= +github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= +github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= +github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= +github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ= +github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -github.com/supranational/blst v0.3.14 h1:xNMoHRJOTwMn63ip6qoWJ2Ymgvj7E2b9jY2FAwY+qRo= -github.com/supranational/blst v0.3.14/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= -github.com/supranational/blst v0.3.15 h1:rd9viN6tfARE5wv3KZJ9H8e1cg0jXW8syFCcsbHa76o= -github.com/supranational/blst v0.3.15/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +github.com/supranational/blst v0.3.16 h1:bTDadT+3fK497EvLdWRQEjiGnUtzJ7jjIUMF0jqwYhE= +github.com/supranational/blst v0.3.16/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= -github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= -github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= -github.com/tklauser/go-sysconf v0.3.15 h1:VE89k0criAymJ/Os65CSn1IXaol+1wrsFHEB8Ol49K4= -github.com/tklauser/go-sysconf v0.3.15/go.mod h1:Dmjwr6tYFIseJw7a3dRLJfsHAMXZ3nEnL/aZY+0IuI4= -github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= -github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= -github.com/tklauser/numcpus v0.10.0 h1:18njr6LDBk1zuna922MgdjQuJFjrdppsZG60sHGfjso= -github.com/tklauser/numcpus v0.10.0/go.mod h1:BiTKazU708GQTYF4mB+cmlpT2Is1gLk7XVuEeem8LsQ= +github.com/tklauser/go-sysconf v0.3.16 h1:frioLaCQSsF5Cy1jgRBrzr6t502KIIwQ0MArYICU0nA= +github.com/tklauser/go-sysconf v0.3.16/go.mod h1:/qNL9xxDhc7tx3HSRsLWNnuzbVfh3e7gh/BmM179nYI= +github.com/tklauser/numcpus v0.11.0 h1:nSTwhKH5e1dMNsCdVBukSZrURJRoHbSEQjdEbY+9RXw= +github.com/tklauser/numcpus v0.11.0/go.mod h1:z+LwcLq54uWZTX0u/bGobaV34u6V7KNlTZejzM6/3MQ= github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w= github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ= github.com/x-cray/logrus-prefixed-formatter v0.5.2 h1:00txxvfBM9muc0jiLIEAkAcIMJzfthRT6usrui8uGmg= @@ -281,40 +293,28 @@ github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGC github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= -golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM= -golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY= -golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI= -golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8= +gitlab.com/hfuss/mux-prometheus v0.0.5 h1:Kcqyiekx8W2dO1EHg+6wOL1F0cFNgRO1uCK18V31D0s= +gitlab.com/hfuss/mux-prometheus v0.0.5/go.mod h1:xcedy8rVGr9TFgRu2urfGuh99B4NdfYdpE4aUMQ0dxA= +go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= +go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU= +golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0= golang.org/x/exp v0.0.0-20240110193028-0dcbfd608b1e h1:723BNChdd0c2Wk6WOE320qGBiPtYx0F0Bbm1kriShfE= golang.org/x/exp v0.0.0-20240110193028-0dcbfd608b1e/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= -golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw= -golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA= -golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE= -golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg= -golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I= -golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY= -golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw= -golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= -golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= -golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= +golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY= +golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU= +golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4= +golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA= -golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= -golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k= -golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -golang.org/x/term v0.33.0 h1:NuFncQrRcaRvVmgRkvM3j/F00gWIAlcmlB8ACEKmGIg= -golang.org/x/term v0.33.0/go.mod h1:s18+ql9tYWp1IfpV9DmCtQDDSRBUjKaw9M1eAv5UeF0= -golang.org/x/term v0.35.0 h1:bZBVKBudEyhRcajGcNc3jIfWPqV4y/Kt2XcoigOWtDQ= -golang.org/x/term v0.35.0/go.mod h1:TPGtkTLesOwf2DE8CgVYiZinHAOuy5AYUYT1lENIZnA= -golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4= -golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU= -golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk= -golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4= +golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk= +golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/term v0.38.0 h1:PQ5pkm/rLO6HnxFR7N2lJHOZX6Kez5Y1gDSJla6jo7Q= +golang.org/x/term v0.38.0/go.mod h1:bSEAKrOT1W+VSu9TSCMtoGEOUcKxOKgl3LE5QEF/xVg= +golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU= +golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY= golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY= golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= @@ -322,6 +322,8 @@ google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWn 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= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= @@ -333,13 +335,7 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8= gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= -gorm.io/driver/sqlite v1.5.6 h1:fO/X46qn5NUEEOZtnjJRWRzZMe8nqJiQ9E+0hi+hKQE= -gorm.io/driver/sqlite v1.5.6/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4= gorm.io/driver/sqlite v1.6.0 h1:WHRRrIiulaPiPFmDcod6prc4l2VGVWHz80KspNsxSfQ= gorm.io/driver/sqlite v1.6.0/go.mod h1:AO9V1qIQddBESngQUKWL9yoH93HIeA1X6V633rBwyT8= -gorm.io/gorm v1.30.0 h1:qbT5aPv1UH8gI99OsRlvDToLxW5zR7FzS9acZDOZcgs= -gorm.io/gorm v1.30.0/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE= -gorm.io/gorm v1.30.5 h1:dvEfYwxL+i+xgCNSGGBT1lDjCzfELK8fHZxL3Ee9X0s= -gorm.io/gorm v1.30.5/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE= -gorm.io/gorm v1.31.0 h1:0VlycGreVhK7RF/Bwt51Fk8v0xLiiiFdbGDPIZQ7mJY= -gorm.io/gorm v1.31.0/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs= +gorm.io/gorm v1.31.1 h1:7CA8FTFz/gRfgqgpeKIBcervUn3xSyPUmr6B2WXJ7kg= +gorm.io/gorm v1.31.1/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs= diff --git a/go-sdk/integration-test/common/db.go b/go-sdk/integration-test/common/db.go index eb509655..f24bd83b 100644 --- a/go-sdk/integration-test/common/db.go +++ b/go-sdk/integration-test/common/db.go @@ -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" @@ -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 } diff --git a/go-sdk/integration-test/common/smt.go b/go-sdk/integration-test/common/smt.go index c40a3a6a..7b379b16 100644 --- a/go-sdk/integration-test/common/smt.go +++ b/go-sdk/integration-test/common/smt.go @@ -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" @@ -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) diff --git a/go-sdk/integration-test/db_test.go b/go-sdk/integration-test/db_test.go index 34368b90..2875402a 100644 --- a/go-sdk/integration-test/db_test.go +++ b/go-sdk/integration-test/db_test.go @@ -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" @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/go-sdk/integration-test/e2e_anon_nullifier_test.go b/go-sdk/integration-test/e2e_anon_nullifier_test.go index 1a1f9bc9..7dc56a68 100644 --- a/go-sdk/integration-test/e2e_anon_nullifier_test.go +++ b/go-sdk/integration-test/e2e_anon_nullifier_test.go @@ -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) diff --git a/go-sdk/integration-test/e2e_nf_anon_nullifier_test.go b/go-sdk/integration-test/e2e_nf_anon_nullifier_test.go index 451070a1..1e082cee 100644 --- a/go-sdk/integration-test/e2e_nf_anon_nullifier_test.go +++ b/go-sdk/integration-test/e2e_nf_anon_nullifier_test.go @@ -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) diff --git a/go-sdk/integration-test/eth_e2e/resources/besu/config.toml b/go-sdk/integration-test/eth_e2e/resources/besu/config.toml index c11ebff0..5deac584 100644 --- a/go-sdk/integration-test/eth_e2e/resources/besu/config.toml +++ b/go-sdk/integration-test/eth_e2e/resources/besu/config.toml @@ -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 diff --git a/go-sdk/integration-test/eth_e2e/resources/besu/genesis.json b/go-sdk/integration-test/eth_e2e/resources/besu/genesis.json index 990bb3bb..5a362a59 100644 --- a/go-sdk/integration-test/eth_e2e/resources/besu/genesis.json +++ b/go-sdk/integration-test/eth_e2e/resources/besu/genesis.json @@ -8,7 +8,8 @@ "blockperiodseconds": 1, "epochlength": 30000, "requesttimeoutseconds": 4 - } + }, + "contractSizeLimit": 2147483647 }, "nonce": "0x0", "timestamp": "0x58ee40ba", diff --git a/go-sdk/integration-test/smt_test.go b/go-sdk/integration-test/smt_test.go index 077d9c5a..57126b08 100644 --- a/go-sdk/integration-test/smt_test.go +++ b/go-sdk/integration-test/smt_test.go @@ -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" @@ -72,6 +73,7 @@ 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)) @@ -79,8 +81,8 @@ 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 := 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) diff --git a/go-sdk/internal/crypto/hash/keccak256.go b/go-sdk/internal/crypto/hash/keccak256.go new file mode 100644 index 00000000..44eb6acc --- /dev/null +++ b/go-sdk/internal/crypto/hash/keccak256.go @@ -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 +} diff --git a/go-sdk/internal/crypto/hash/keccak256_test.go b/go-sdk/internal/crypto/hash/keccak256_test.go new file mode 100644 index 00000000..d0326b9c --- /dev/null +++ b/go-sdk/internal/crypto/hash/keccak256_test.go @@ -0,0 +1,137 @@ +// 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 ( + "math/big" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestKeccak256Hasher_Hash_MultipleInputs1(t *testing.T) { + hasher := &Keccak256Hasher{} + v1, _ := new(big.Int).SetString("20349940423862035287868699599764962454537984981628200184279725786303353984557", 10) + v2, _ := new(big.Int).SetString("10955310555638083816119775899206389561202556659568675876759181443512300421331", 10) + inputs := []*big.Int{ + v1, + v2, + } + + result, err := hasher.Hash(inputs) + if err != nil { + t.Fatalf("Hash() failed: %v", err) + } + + if result == nil { + t.Fatal("expected non-nil hash result") + } + + expected, _ := new(big.Int).SetString("b7fc494a5f5f4706631139167310f9e2c63b7854e2d25c85026a0626d583880d", 16) + assert.Equal(t, expected, result) +} + +func TestKeccak256Hasher_Hash_MultipleInputs2(t *testing.T) { + hasher := &Keccak256Hasher{} + v1 := big.NewInt(10) + v2, _ := new(big.Int).SetString("43c49e8ba68a9b8a6bb5c230a734d8271a83d2f63722e7651272ebeef5446e", 16) + v3, _ := new(big.Int).SetString("9198063289874244593808956064764348354864043212453245695133881114917754098693", 10) + v4, _ := new(big.Int).SetString("3600411115173311692823743444460566395943576560299970643507632418781961416843", 10) + + inputs := []*big.Int{ + v1, + v2, + v3, + v4, + } + + result, err := hasher.Hash(inputs) + if err != nil { + t.Fatalf("Hash() failed: %v", err) + } + + if result == nil { + t.Fatal("expected non-nil hash result") + } + + expected, _ := new(big.Int).SetString("53996271411897636657568875696445326528866233548845021678036249293076239906883", 10) + assert.Equal(t, expected, result) +} + +func TestKeccak256Hasher_Hash_ZeroValue(t *testing.T) { + hasher := &Keccak256Hasher{} + inputs := []*big.Int{big.NewInt(0)} + + result, err := hasher.Hash(inputs) + if err != nil { + t.Fatalf("Hash() with zero value failed: %v", err) + } + + if result == nil { + t.Fatal("expected non-nil hash result for zero input") + } +} + +func TestKeccak256Hasher_Hash_LargeNumbers(t *testing.T) { + hasher := &Keccak256Hasher{} + + largeNum := new(big.Int).Sub( + new(big.Int).Lsh(big.NewInt(1), 256), + big.NewInt(1), + ) + + inputs := []*big.Int{largeNum} + + result, err := hasher.Hash(inputs) + if err != nil { + t.Fatalf("Hash() with large number failed: %v", err) + } + + if result == nil { + t.Fatal("expected non-nil hash result for large number") + } +} + +func TestKeccak256Hasher_Hash_EmptySlice(t *testing.T) { + hasher := &Keccak256Hasher{} + inputs := []*big.Int{} + + result, err := hasher.Hash(inputs) + if err != nil { + t.Fatalf("Hash() with empty slice failed: %v", err) + } + + if result == nil { + t.Fatal("expected non-nil hash result for empty slice") + } +} + +func TestKeccak256Hasher_CheckInRange(t *testing.T) { + hasher := &Keccak256Hasher{} + + // Test with a value in range + inRange := new(big.Int).SetUint64(1234567890) + if !hasher.CheckInRange(inRange) { + t.Errorf("CheckInRange() failed for in-range value: %s", inRange.String()) + } + + // Test with a value out of range (greater than 2^256 - 1) + outOfRange := new(big.Int).Lsh(big.NewInt(1), 256) + if hasher.CheckInRange(outOfRange) { + t.Errorf("CheckInRange() should have failed for out-of-range value: %s", outOfRange.String()) + } +} diff --git a/go-sdk/internal/crypto/hash/poseidon.go b/go-sdk/internal/crypto/hash/poseidon.go new file mode 100644 index 00000000..cd4ed9b6 --- /dev/null +++ b/go-sdk/internal/crypto/hash/poseidon.go @@ -0,0 +1,34 @@ +// 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 ( + "math/big" + + "github.com/iden3/go-iden3-crypto/poseidon" + "github.com/iden3/go-iden3-crypto/utils" +) + +type PoseidonHasher struct{} + +func (p *PoseidonHasher) Hash(inputs []*big.Int) (*big.Int, error) { + return poseidon.Hash(inputs) +} + +func (p *PoseidonHasher) CheckInRange(a *big.Int) bool { + return utils.CheckBigIntInField(a) +} diff --git a/go-sdk/internal/sparse-merkle-tree/node/fungible.go b/go-sdk/internal/sparse-merkle-tree/node/fungible.go index b967d507..94b974fc 100644 --- a/go-sdk/internal/sparse-merkle-tree/node/fungible.go +++ b/go-sdk/internal/sparse-merkle-tree/node/fungible.go @@ -21,6 +21,7 @@ import ( "github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/core" coreUTXO "github.com/hyperledger-labs/zeto/go-sdk/pkg/utxo" + apicore "github.com/hyperledger-labs/zeto/go-sdk/pkg/utxo/core" "github.com/iden3/go-iden3-crypto/babyjub" ) @@ -28,23 +29,29 @@ type fungibleNode struct { Amount *big.Int Owner *babyjub.PublicKey Salt *big.Int + hasher apicore.Hasher } -func NewFungible(amount *big.Int, owner *babyjub.PublicKey, salt *big.Int) *fungibleNode { +func NewFungible(amount *big.Int, owner *babyjub.PublicKey, salt *big.Int, hasher apicore.Hasher) *fungibleNode { return &fungibleNode{ Amount: amount, Owner: owner, Salt: salt, + hasher: hasher, } } func (f *fungibleNode) CalculateIndex() (core.NodeIndex, error) { - u := coreUTXO.NewFungible(f.Amount, f.Owner, f.Salt) + u := coreUTXO.NewFungible(f.Amount, f.Owner, f.Salt, f.hasher) hash, err := u.GetHash() if err != nil { return nil, err } - return NewNodeIndexFromBigInt(hash) + return NewNodeIndexFromBigInt(hash, f.hasher) +} + +func (f *fungibleNode) GetHasher() apicore.Hasher { + return f.hasher } // the "Owner" is the private key that must be properly hashed and trimmed to be @@ -54,21 +61,27 @@ type fungibleNullifierNode struct { Amount *big.Int Owner *big.Int Salt *big.Int + hasher apicore.Hasher } -func NewFungibleNullifier(amount *big.Int, owner *big.Int, salt *big.Int) *fungibleNullifierNode { +func NewFungibleNullifier(amount *big.Int, owner *big.Int, salt *big.Int, hasher apicore.Hasher) *fungibleNullifierNode { return &fungibleNullifierNode{ Amount: amount, Owner: owner, Salt: salt, + hasher: hasher, } } func (f *fungibleNullifierNode) CalculateIndex() (core.NodeIndex, error) { - u := coreUTXO.NewFungibleNullifier(f.Amount, f.Owner, f.Salt) + u := coreUTXO.NewFungibleNullifier(f.Amount, f.Owner, f.Salt, f.hasher) hash, err := u.GetHash() if err != nil { return nil, err } - return NewNodeIndexFromBigInt(hash) + return NewNodeIndexFromBigInt(hash, f.hasher) +} + +func (f *fungibleNullifierNode) GetHasher() apicore.Hasher { + return f.hasher } diff --git a/go-sdk/internal/sparse-merkle-tree/node/fungible_test.go b/go-sdk/internal/sparse-merkle-tree/node/fungible_test.go index f85ec207..e040528d 100644 --- a/go-sdk/internal/sparse-merkle-tree/node/fungible_test.go +++ b/go-sdk/internal/sparse-merkle-tree/node/fungible_test.go @@ -20,6 +20,7 @@ import ( "math/big" "testing" + "github.com/hyperledger-labs/zeto/go-sdk/internal/crypto/hash" "github.com/iden3/go-iden3-crypto/babyjub" "github.com/stretchr/testify/assert" ) @@ -32,7 +33,7 @@ func TestFungibleUTXOs(t *testing.T) { Y: y, } salt, _ := new(big.Int).SetString("13de02d64a5736a56b2d35d2a83dd60397ba70aae6f8347629f0960d4fee5d58", 16) - utxo1 := NewFungible(big.NewInt(10), alice, salt) + utxo1 := NewFungible(big.NewInt(10), alice, salt, &hash.PoseidonHasher{}) idx1, err := utxo1.CalculateIndex() assert.NoError(t, err) @@ -42,7 +43,7 @@ func TestFungibleUTXOs(t *testing.T) { func TestFungibleUTXOsWithNullifiers(t *testing.T) { privateKey, _ := new(big.Int).SetString("df7ff8191db562f4ed9404e91f184502fe67f880cd1fe67c0f84d224a53ee55", 16) salt, _ := new(big.Int).SetString("13de02d64a5736a56b2d35d2a83dd60397ba70aae6f8347629f0960d4fee5d58", 16) - utxo1 := NewFungibleNullifier(big.NewInt(10), privateKey, salt) + utxo1 := NewFungibleNullifier(big.NewInt(10), privateKey, salt, &hash.PoseidonHasher{}) idx1, err := utxo1.CalculateIndex() assert.NoError(t, err) @@ -57,7 +58,7 @@ func TestFungibleUTXOsFail(t *testing.T) { Y: y, } salt, _ := new(big.Int).SetString("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16) - utxo1 := NewFungible(big.NewInt(10), alice, salt) + utxo1 := NewFungible(big.NewInt(10), alice, salt, &hash.PoseidonHasher{}) _, err := utxo1.CalculateIndex() assert.EqualError(t, err, "inputs values not inside Finite Field") @@ -66,7 +67,7 @@ func TestFungibleUTXOsFail(t *testing.T) { func TestFungibleUTXOsWithNullifiersFail(t *testing.T) { privateKey, _ := new(big.Int).SetString("df7ff8191db562f4ed9404e91f184502fe67f880cd1fe67c0f84d224a53ee55", 16) salt, _ := new(big.Int).SetString("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16) - utxo1 := NewFungibleNullifier(big.NewInt(10), privateKey, salt) + utxo1 := NewFungibleNullifier(big.NewInt(10), privateKey, salt, &hash.PoseidonHasher{}) _, err := utxo1.CalculateIndex() assert.EqualError(t, err, "inputs values not inside Finite Field") diff --git a/go-sdk/internal/sparse-merkle-tree/node/node.go b/go-sdk/internal/sparse-merkle-tree/node/node.go index d94efd76..35c35f1e 100644 --- a/go-sdk/internal/sparse-merkle-tree/node/node.go +++ b/go-sdk/internal/sparse-merkle-tree/node/node.go @@ -21,19 +21,22 @@ import ( "math/big" "strings" + "github.com/hyperledger-labs/zeto/go-sdk/internal/crypto/hash" "github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/core" - "github.com/iden3/go-iden3-crypto/poseidon" - cryptoUtils "github.com/iden3/go-iden3-crypto/utils" + apicore "github.com/hyperledger-labs/zeto/go-sdk/pkg/utxo/core" ) const INDEX_BYTES_LEN = 32 -var ZERO_INDEX, _ = NewNodeIndexFromBigInt(big.NewInt(0)) +var ZERO_INDEX, _ = NewNodeIndexFromBigInt(big.NewInt(0), &hash.PoseidonHasher{}) // nodeIndex is a wrapper around []byte to implement the NodeIndex interface. // it's a 256-bit number. the path from the root node to a leaf node is determined // by the index's bits. 0 means go left, 1 means go right. -type nodeIndex [32]byte +type nodeIndex struct { + index [32]byte + hasher apicore.Hasher +} // node is an implementation of the Node interface type node struct { @@ -54,17 +57,14 @@ func NewEmptyNode() core.Node { // the value parameter is optional. if "nil", the index hash is used in the // place of the value when calculating the node reference hash (aka "node key"). -func NewLeafNode(s core.Indexable, v ...*big.Int) (core.Node, error) { +func NewLeafNode(s core.Indexable, v *big.Int) (core.Node, error) { n := &node{nodeType: core.NodeTypeLeaf, state: s} idx, err := n.state.CalculateIndex() if err != nil { return nil, err } n.i = idx - - if len(v) > 0 { - n.v = v[0] - } + n.v = v // the leaf node's reference is calculated as follows: // 1. get the node's index, call it hKey @@ -76,22 +76,22 @@ func NewLeafNode(s core.Indexable, v ...*big.Int) (core.Node, error) { hValue = hKey } elements := []*big.Int{hKey, hValue, big.NewInt(1)} - hash, err := poseidon.Hash(elements) + hash, err := s.GetHasher().Hash(elements) if err != nil { return nil, err } - n.refKey, err = NewNodeIndexFromBigInt(hash) + n.refKey, err = NewNodeIndexFromBigInt(hash, s.GetHasher()) return n, err } -func NewBranchNode(leftChild, rightChild core.NodeRef) (core.Node, error) { +func NewBranchNode(leftChild, rightChild core.NodeRef, hasher apicore.Hasher) (core.Node, error) { n := &node{nodeType: core.NodeTypeBranch, leftChild: leftChild, rightChild: rightChild} elements := []*big.Int{leftChild.BigInt(), rightChild.BigInt()} - hash, err := poseidon.Hash(elements) + hash, err := hasher.Hash(elements) if err != nil { return nil, err } - n.refKey, err = NewNodeIndexFromBigInt(hash) + n.refKey, err = NewNodeIndexFromBigInt(hash, hasher) return n, err } @@ -121,19 +121,19 @@ func (n *node) RightChild() core.NodeRef { // ////////////////////////////////////// // implementation of nodeIndex -func NewNodeIndexFromBigInt(i *big.Int) (core.NodeIndex, error) { +func NewNodeIndexFromBigInt(i *big.Int, hasher apicore.Hasher) (core.NodeIndex, error) { // verfy that the integer are valid and fit inside the Finite Field. - if !cryptoUtils.CheckBigIntInField(i) { + if !hasher.CheckInRange(i) { return nil, ErrNodeIndexTooLarge } - idx := new(nodeIndex) - copy(idx[:], swapEndianness(i.Bytes())) + idx := &nodeIndex{hasher: hasher} + copy(idx.index[:], swapEndianness(i.Bytes())) return idx, nil } // NewNodeIndexFromHex creates a new NodeIndex from a hex string that // represents the index in big-endian format. -func NewNodeIndexFromHex(h string) (core.NodeIndex, error) { +func NewNodeIndexFromHex(h string, hasher apicore.Hasher) (core.NodeIndex, error) { h = strings.TrimPrefix(h, "0x") b, err := hex.DecodeString(h) if err != nil { @@ -142,17 +142,17 @@ func NewNodeIndexFromHex(h string) (core.NodeIndex, error) { if len(b) != INDEX_BYTES_LEN { return nil, ErrNodeBytesBadSize } - idx := new(nodeIndex) - copy(idx[:], b) + idx := &nodeIndex{hasher: hasher} + copy(idx.index[:], b) return idx, nil } func (idx *nodeIndex) BigInt() *big.Int { - return new(big.Int).SetBytes(swapEndianness(idx[:])) + return new(big.Int).SetBytes(swapEndianness(idx.index[:])) } func (idx *nodeIndex) Hex() string { - return hex.EncodeToString(idx[:]) + return hex.EncodeToString(idx.index[:]) } func (idx *nodeIndex) IsZero() bool { @@ -163,6 +163,10 @@ func (idx *nodeIndex) Equal(other core.NodeRef) bool { return idx.BigInt().Cmp(other.BigInt()) == 0 } +func (idx *nodeIndex) GetHasher() apicore.Hasher { + return idx.hasher +} + // getPath returns the binary path, from the root to the leaf. func (idx *nodeIndex) ToPath(levels int) []bool { path := make([]bool, levels) @@ -176,7 +180,7 @@ func (idx *nodeIndex) IsBitOne(pos uint) bool { if pos >= 256 { return false } - return (idx[pos/8] & (1 << (pos % 8))) != 0 + return (idx.index[pos/8] & (1 << (pos % 8))) != 0 } // swapEndianness swaps the order of the bytes in the byte array of a node index. diff --git a/go-sdk/internal/sparse-merkle-tree/node/node_test.go b/go-sdk/internal/sparse-merkle-tree/node/node_test.go index 60c6e5bd..0b41db9d 100644 --- a/go-sdk/internal/sparse-merkle-tree/node/node_test.go +++ b/go-sdk/internal/sparse-merkle-tree/node/node_test.go @@ -21,31 +21,34 @@ 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/utils" "github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/core" + apicore "github.com/hyperledger-labs/zeto/go-sdk/pkg/utxo/core" "github.com/iden3/go-iden3-crypto/poseidon" "github.com/stretchr/testify/assert" ) func TestNodeIndex(t *testing.T) { - idx0, _ := NewNodeIndexFromBigInt(big.NewInt(0)) + hasher := &hash.PoseidonHasher{} + idx0, _ := NewNodeIndexFromBigInt(big.NewInt(0), hasher) assert.Equal(t, "0000000000000000000000000000000000000000000000000000000000000000", idx0.Hex()) - idx1, _ := NewNodeIndexFromBigInt(big.NewInt(1)) + idx1, _ := NewNodeIndexFromBigInt(big.NewInt(1), hasher) assert.Equal(t, "0100000000000000000000000000000000000000000000000000000000000000", idx1.Hex()) - idx2, _ := NewNodeIndexFromBigInt(big.NewInt(10)) + idx2, _ := NewNodeIndexFromBigInt(big.NewInt(10), hasher) assert.Equal(t, "0a00000000000000000000000000000000000000000000000000000000000000", idx2.Hex()) - idx3, _ := NewNodeIndexFromBigInt(big.NewInt(12345678)) + idx3, _ := NewNodeIndexFromBigInt(big.NewInt(12345678), hasher) assert.Equal(t, "4e61bc0000000000000000000000000000000000000000000000000000000000", idx3.Hex()) v4, _ := new(big.Int).SetString("4932297968297298434239270129193057052722409868268166443802652458940273154854", 10) - idx4, _ := NewNodeIndexFromBigInt(v4) + idx4, _ := NewNodeIndexFromBigInt(v4, hasher) assert.Equal(t, "265baaf161e875c372d08e50f52abddc01d32efc93e90290bb8b3d9ceb94e70a", idx4.Hex()) expectedBytes4 := []byte{38, 91, 170, 241, 97, 232, 117, 195, 114, 208, 142, 80, 245, 42, 189, 220, 1, 211, 46, 252, 147, 233, 2, 144, 187, 139, 61, 156, 235, 148, 231, 10} rawIndex4 := idx4.(*nodeIndex) - assert.Equal(t, expectedBytes4, rawIndex4[:]) + assert.Equal(t, expectedBytes4, rawIndex4.index[:]) - idx5, err := NewNodeIndexFromHex("265baaf161e875c372d08e50f52abddc01d32efc93e90290bb8b3d9ceb94e70a") + idx5, err := NewNodeIndexFromHex("265baaf161e875c372d08e50f52abddc01d32efc93e90290bb8b3d9ceb94e70a", hasher) assert.NoError(t, err) assert.Equal(t, 0, v4.Cmp(idx5.BigInt())) } @@ -60,9 +63,9 @@ func TestNewEmptyNode(t *testing.T) { } func TestNewLeafNode(t *testing.T) { - idx, _ := NewNodeIndexFromBigInt(big.NewInt(10)) + idx, _ := NewNodeIndexFromBigInt(big.NewInt(10), &hash.PoseidonHasher{}) i := utils.NewIndexOnly(idx) - node, err := NewLeafNode(i) + node, err := NewLeafNode(i, nil) assert.NoError(t, err) assert.Equal(t, node.Type(), core.NodeTypeLeaf) assert.Equal(t, node.Index(), idx) @@ -74,8 +77,23 @@ func TestNewLeafNode(t *testing.T) { assert.Nil(t, node.RightChild()) } +func TestNewLeafNodeKeccak256(t *testing.T) { + idx, _ := NewNodeIndexFromBigInt(big.NewInt(10), &hash.Keccak256Hasher{}) + i := utils.NewIndexOnly(idx) + node, err := NewLeafNode(i, nil) + assert.NoError(t, err) + assert.Equal(t, node.Type(), core.NodeTypeLeaf) + assert.Equal(t, node.Index(), idx) + elements := []*big.Int{idx.BigInt(), idx.BigInt(), big.NewInt(1)} + hash, err := (&hash.Keccak256Hasher{}).Hash(elements) + assert.NoError(t, err) + assert.Equal(t, node.Ref().BigInt(), hash) + assert.Nil(t, node.LeftChild()) + assert.Nil(t, node.RightChild()) +} + func TestNewLeafNodeWithValue(t *testing.T) { - idx, _ := NewNodeIndexFromBigInt(big.NewInt(10)) + idx, _ := NewNodeIndexFromBigInt(big.NewInt(10), &hash.PoseidonHasher{}) i := utils.NewIndexOnly(idx) node, err := NewLeafNode(i, big.NewInt(12345)) assert.NoError(t, err) @@ -90,9 +108,9 @@ func TestNewLeafNodeWithValue(t *testing.T) { } func TestNewBranchNode(t *testing.T) { - idx0, _ := NewNodeIndexFromBigInt(big.NewInt(0)) - idx1, _ := NewNodeIndexFromBigInt(big.NewInt(1)) - node, err := NewBranchNode(idx0, idx1) + idx0, _ := NewNodeIndexFromBigInt(big.NewInt(0), &hash.PoseidonHasher{}) + idx1, _ := NewNodeIndexFromBigInt(big.NewInt(1), &hash.PoseidonHasher{}) + node, err := NewBranchNode(idx0, idx1, &hash.PoseidonHasher{}) assert.NoError(t, err) assert.Equal(t, node.Type(), core.NodeTypeBranch) assert.Nil(t, node.Index()) @@ -109,8 +127,11 @@ type badIndex struct{} func (f *badIndex) CalculateIndex() (core.NodeIndex, error) { return nil, errors.New("Bang!") } +func (f *badIndex) GetHasher() apicore.Hasher { + return &hash.PoseidonHasher{} +} func TestNewLeafNodeFail(t *testing.T) { - _, err := NewLeafNode(&badIndex{}) + _, err := NewLeafNode(&badIndex{}, nil) assert.EqualError(t, err, "Bang!") } diff --git a/go-sdk/internal/sparse-merkle-tree/node/nonfungible.go b/go-sdk/internal/sparse-merkle-tree/node/nonfungible.go index fbb050e0..8b606184 100644 --- a/go-sdk/internal/sparse-merkle-tree/node/nonfungible.go +++ b/go-sdk/internal/sparse-merkle-tree/node/nonfungible.go @@ -21,6 +21,7 @@ import ( "github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/core" coreUTXO "github.com/hyperledger-labs/zeto/go-sdk/pkg/utxo" + apicore "github.com/hyperledger-labs/zeto/go-sdk/pkg/utxo/core" "github.com/iden3/go-iden3-crypto/babyjub" ) @@ -29,24 +30,30 @@ type nonFungibleNode struct { TokenUri string Owner *babyjub.PublicKey Salt *big.Int + hasher apicore.Hasher } -func NewNonFungible(tokenId *big.Int, tokenUri string, owner *babyjub.PublicKey, salt *big.Int) *nonFungibleNode { +func NewNonFungible(tokenId *big.Int, tokenUri string, owner *babyjub.PublicKey, salt *big.Int, hasher apicore.Hasher) *nonFungibleNode { return &nonFungibleNode{ TokenId: tokenId, TokenUri: tokenUri, Owner: owner, Salt: salt, + hasher: hasher, } } func (f *nonFungibleNode) CalculateIndex() (core.NodeIndex, error) { - u := coreUTXO.NewNonFungible(f.TokenId, f.TokenUri, f.Owner, f.Salt) + u := coreUTXO.NewNonFungible(f.TokenId, f.TokenUri, f.Owner, f.Salt, f.hasher) hash, err := u.GetHash() if err != nil { return nil, err } - return NewNodeIndexFromBigInt(hash) + return NewNodeIndexFromBigInt(hash, f.hasher) +} + +func (f *nonFungibleNode) GetHasher() apicore.Hasher { + return f.hasher } // the "Owner" is the private key that must be properly hashed and trimmed to be @@ -57,22 +64,28 @@ type nonFungibleNullifierNode struct { TokenUri string Owner *big.Int Salt *big.Int + hasher apicore.Hasher } -func NewNonFungibleNullifier(tokenId *big.Int, tokenUri string, owner *big.Int, salt *big.Int) *nonFungibleNullifierNode { +func NewNonFungibleNullifier(tokenId *big.Int, tokenUri string, owner *big.Int, salt *big.Int, hasher apicore.Hasher) *nonFungibleNullifierNode { return &nonFungibleNullifierNode{ TokenId: tokenId, TokenUri: tokenUri, Owner: owner, Salt: salt, + hasher: hasher, } } func (f *nonFungibleNullifierNode) CalculateIndex() (core.NodeIndex, error) { - u := coreUTXO.NewNonFungibleNullifier(f.TokenId, f.TokenUri, f.Owner, f.Salt) + u := coreUTXO.NewNonFungibleNullifier(f.TokenId, f.TokenUri, f.Owner, f.Salt, f.hasher) hash, err := u.GetHash() if err != nil { return nil, err } - return NewNodeIndexFromBigInt(hash) + return NewNodeIndexFromBigInt(hash, f.hasher) +} + +func (f *nonFungibleNullifierNode) GetHasher() apicore.Hasher { + return f.hasher } diff --git a/go-sdk/internal/sparse-merkle-tree/node/nonfungible_test.go b/go-sdk/internal/sparse-merkle-tree/node/nonfungible_test.go index 5bda2c10..6631dc9d 100644 --- a/go-sdk/internal/sparse-merkle-tree/node/nonfungible_test.go +++ b/go-sdk/internal/sparse-merkle-tree/node/nonfungible_test.go @@ -20,6 +20,7 @@ import ( "math/big" "testing" + "github.com/hyperledger-labs/zeto/go-sdk/internal/crypto/hash" "github.com/iden3/go-iden3-crypto/babyjub" "github.com/stretchr/testify/assert" ) @@ -33,7 +34,7 @@ func TestNonFungibleUTXOs(t *testing.T) { } salt, _ := new(big.Int).SetString("14366367216420666010683918465570547601749064763665615379119566396413295472937", 10) uri := "http://ipfs.io/file-hash-1" - utxo1 := NewNonFungible(big.NewInt(1001), uri, alice, salt) + utxo1 := NewNonFungible(big.NewInt(1001), uri, alice, salt, &hash.PoseidonHasher{}) idx1, err := utxo1.CalculateIndex() assert.NoError(t, err) @@ -44,7 +45,7 @@ func TestNonFungibleUTXOsWithNullifiers(t *testing.T) { privateKey, _ := new(big.Int).SetString("df7ff8191db562f4ed9404e91f184502fe67f880cd1fe67c0f84d224a53ee55", 16) salt, _ := new(big.Int).SetString("14366367216420666010683918465570547601749064763665615379119566396413295472937", 10) uri := "http://ipfs.io/file-hash-1" - utxo1 := NewNonFungibleNullifier(big.NewInt(1001), uri, privateKey, salt) + utxo1 := NewNonFungibleNullifier(big.NewInt(1001), uri, privateKey, salt, &hash.PoseidonHasher{}) idx1, err := utxo1.CalculateIndex() assert.NoError(t, err) @@ -60,7 +61,7 @@ func TestNonFungibleUTXOsFail(t *testing.T) { } salt, _ := new(big.Int).SetString("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16) uri := "http://ipfs.io/file-hash-1" - utxo1 := NewNonFungible(big.NewInt(1001), uri, alice, salt) + utxo1 := NewNonFungible(big.NewInt(1001), uri, alice, salt, &hash.PoseidonHasher{}) _, err := utxo1.CalculateIndex() assert.EqualError(t, err, "inputs values not inside Finite Field") } @@ -69,7 +70,7 @@ func TestNonFungibleUTXOsWithNullifiersFail(t *testing.T) { privateKey, _ := new(big.Int).SetString("df7ff8191db562f4ed9404e91f184502fe67f880cd1fe67c0f84d224a53ee55", 16) salt, _ := new(big.Int).SetString("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16) uri := "http://ipfs.io/file-hash-1" - utxo1 := NewNonFungibleNullifier(big.NewInt(1001), uri, privateKey, salt) + utxo1 := NewNonFungibleNullifier(big.NewInt(1001), uri, privateKey, salt, &hash.PoseidonHasher{}) _, err := utxo1.CalculateIndex() assert.EqualError(t, err, "inputs values not inside Finite Field") } diff --git a/go-sdk/internal/sparse-merkle-tree/smt/merkletree.go b/go-sdk/internal/sparse-merkle-tree/smt/merkletree.go index 8895e197..0fb51fad 100644 --- a/go-sdk/internal/sparse-merkle-tree/smt/merkletree.go +++ b/go-sdk/internal/sparse-merkle-tree/smt/merkletree.go @@ -25,6 +25,7 @@ import ( "github.com/hyperledger-labs/zeto/go-sdk/internal/sparse-merkle-tree/node" "github.com/hyperledger-labs/zeto/go-sdk/internal/sparse-merkle-tree/utils" "github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/core" + apicore "github.com/hyperledger-labs/zeto/go-sdk/pkg/utxo/core" ) // MAX_TREE_HEIGHT is the maximum number of levels of the sparse merkle tree. @@ -36,13 +37,14 @@ type sparseMerkleTree struct { db core.Storage rootKey core.NodeRef maxLevels int + hasher apicore.Hasher } func NewMerkleTree(db core.Storage, maxLevels int) (core.SparseMerkleTree, error) { if maxLevels <= 0 || maxLevels > MAX_TREE_HEIGHT { return nil, ErrMaxLevelsNotInRange } - mt := sparseMerkleTree{db: db, maxLevels: maxLevels} + mt := sparseMerkleTree{db: db, maxLevels: maxLevels, hasher: db.GetHasher()} root, err := mt.db.GetRootNodeRef() if err == core.ErrNotFound { @@ -142,10 +144,10 @@ func (mt *sparseMerkleTree) GenerateProofs(keys []*big.Int, rootKey core.NodeRef } func (mt *sparseMerkleTree) generateProof(key *big.Int, rootKey core.NodeRef) (core.Proof, *big.Int, error) { - p := &proof{} + p := &proof{hasher: mt.hasher} var siblingKey core.NodeRef - kHash, err := node.NewNodeIndexFromBigInt(key) + kHash, err := node.NewNodeIndexFromBigInt(key, mt.hasher) if err != nil { return nil, nil, err } @@ -268,7 +270,7 @@ func (mt *sparseMerkleTree) addLeaf(batch core.Transaction, newLeaf core.Node, c return nil, err } // replace the branch node with the new branch node, which now has a new right child - newBranchNode, err = node.NewBranchNode(currentNode.LeftChild(), nextKey) + newBranchNode, err = node.NewBranchNode(currentNode.LeftChild(), nextKey, mt.hasher) } else { // go left log.WithLogField("level", strconv.Itoa(level)).Debug("Found branch node, going left") nextKey, err = mt.addLeaf(batch, newLeaf, currentNode.LeftChild(), level+1, path) @@ -276,7 +278,7 @@ func (mt *sparseMerkleTree) addLeaf(batch core.Transaction, newLeaf core.Node, c return nil, err } // replace the branch node with the new branch node, which now has a new left child - newBranchNode, err = node.NewBranchNode(nextKey, currentNode.RightChild()) + newBranchNode, err = node.NewBranchNode(nextKey, currentNode.RightChild(), mt.hasher) } if err != nil { return nil, err @@ -320,10 +322,10 @@ func (mt *sparseMerkleTree) extendPath(batch core.Transaction, newLeaf core.Node } if pathNewLeaf[level] { // the new branch node returned is on the right - newBranchNode, err = node.NewBranchNode(node.ZERO_INDEX, nextKey) + newBranchNode, err = node.NewBranchNode(node.ZERO_INDEX, nextKey, mt.hasher) } else { // the new branch node returned is on the left - newBranchNode, err = node.NewBranchNode(nextKey, node.ZERO_INDEX) + newBranchNode, err = node.NewBranchNode(nextKey, node.ZERO_INDEX, mt.hasher) } if err != nil { return nil, err @@ -341,10 +343,10 @@ func (mt *sparseMerkleTree) extendPath(batch core.Transaction, newLeaf core.Node var err error if pathNewLeaf[level] { // the new leaf node is on the right - newBranchNode, err = node.NewBranchNode(oldLeafRef, newLeafRef) + newBranchNode, err = node.NewBranchNode(oldLeafRef, newLeafRef, mt.hasher) } else { // the new leaf node is on the left - newBranchNode, err = node.NewBranchNode(newLeafRef, oldLeafRef) + newBranchNode, err = node.NewBranchNode(newLeafRef, oldLeafRef, mt.hasher) } if err != nil { return nil, err diff --git a/go-sdk/internal/sparse-merkle-tree/smt/merkletree_test.go b/go-sdk/internal/sparse-merkle-tree/smt/merkletree_test.go index f904dfde..76609247 100644 --- a/go-sdk/internal/sparse-merkle-tree/smt/merkletree_test.go +++ b/go-sdk/internal/sparse-merkle-tree/smt/merkletree_test.go @@ -20,7 +20,9 @@ import ( "fmt" "testing" + "github.com/hyperledger-labs/zeto/go-sdk/internal/crypto/hash" "github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/core" + apicore "github.com/hyperledger-labs/zeto/go-sdk/pkg/utxo/core" "github.com/stretchr/testify/assert" ) @@ -53,6 +55,9 @@ func (ms *mockStorage) Rollback() error { return nil } func (ms *mockStorage) Close() {} +func (ms *mockStorage) GetHasher() apicore.Hasher { + return &hash.PoseidonHasher{} +} func TestNewMerkleTreeFailures(t *testing.T) { db := &mockStorage{} diff --git a/go-sdk/internal/sparse-merkle-tree/smt/proof.go b/go-sdk/internal/sparse-merkle-tree/smt/proof.go index 4502ade8..91259769 100644 --- a/go-sdk/internal/sparse-merkle-tree/smt/proof.go +++ b/go-sdk/internal/sparse-merkle-tree/smt/proof.go @@ -22,6 +22,7 @@ import ( "github.com/hyperledger-labs/zeto/go-sdk/internal/sparse-merkle-tree/node" "github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/core" + apicore "github.com/hyperledger-labs/zeto/go-sdk/pkg/utxo/core" ) // Proof defines the required elements for a MT proof of existence or @@ -34,6 +35,7 @@ type proof struct { // nonEmptySiblings is a bitmap of non-empty Siblings found in Siblings. This helps // to save space in the proof, by not having to carry around empty nodes. nonEmptySiblings []byte + hasher apicore.Hasher } func (p *proof) IsExistenceProof() bool { @@ -112,11 +114,11 @@ func (p *proof) ToCircomVerifierProof(k, v *big.Int, rootKey core.NodeRef, level cp.OldValue = big.NewInt(0) } var err error - cp.Key, err = node.NewNodeIndexFromBigInt(k) + cp.Key, err = node.NewNodeIndexFromBigInt(k, p.hasher) if err != nil { return nil, err } - cp.Value, err = node.NewNodeIndexFromBigInt(v) + cp.Value, err = node.NewNodeIndexFromBigInt(v, p.hasher) if err != nil { return nil, err } @@ -169,13 +171,13 @@ func calculateRootFromProof(proof *proof, leafNode core.Node) (core.NodeRef, err siblingKey = node.ZERO_INDEX } if path[level] { // go right - branchNode, err := node.NewBranchNode(siblingKey, midKey) + branchNode, err := node.NewBranchNode(siblingKey, midKey, proof.hasher) if err != nil { return nil, err } midKey = branchNode.Ref() } else { // go left - branchNode, err := node.NewBranchNode(midKey, siblingKey) + branchNode, err := node.NewBranchNode(midKey, siblingKey, proof.hasher) if err != nil { return nil, err } diff --git a/go-sdk/internal/sparse-merkle-tree/smt/smt_test.go b/go-sdk/internal/sparse-merkle-tree/smt/smt_test.go index 55fb5a65..ace8fb14 100644 --- a/go-sdk/internal/sparse-merkle-tree/smt/smt_test.go +++ b/go-sdk/internal/sparse-merkle-tree/smt/smt_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/hyperledger-labs/zeto/go-sdk/internal/crypto" + "github.com/hyperledger-labs/zeto/go-sdk/internal/crypto/hash" "github.com/hyperledger-labs/zeto/go-sdk/internal/sparse-merkle-tree/node" "github.com/hyperledger-labs/zeto/go-sdk/internal/sparse-merkle-tree/storage" "github.com/hyperledger-labs/zeto/go-sdk/internal/sparse-merkle-tree/utils" @@ -41,7 +42,6 @@ import ( type MerkleTreeTestSuite struct { suite.Suite - db core.Storage dbfile *os.File gormDB *gorm.DB } @@ -77,8 +77,6 @@ func (s *MerkleTreeTestSuite) SetupTest() { err = db.Table(core.NodesTablePrefix + "test_1").AutoMigrate(&core.SMTNode{}) assert.NoError(s.T(), err) - provider := &testSqlProvider{db: db} - s.db = storage.NewSqlStorage(provider, "test_1") s.gormDB = db } @@ -88,13 +86,18 @@ func (s *MerkleTreeTestSuite) TearDownTest() { } func (s *MerkleTreeTestSuite) TestNewMerkleTree() { - mt, err := NewMerkleTree(s.db, 64) + provider := &testSqlProvider{db: s.gormDB} + db := storage.NewSqlStorage(provider, "test_1", &hash.PoseidonHasher{}) + mt, err := NewMerkleTree(db, 64) assert.NoError(s.T(), err) assert.Equal(s.T(), 0, mt.Root().BigInt().Cmp(big.NewInt(0))) } func (s *MerkleTreeTestSuite) TestAddNode() { - mt, err := NewMerkleTree(s.db, 64) + provider := &testSqlProvider{db: s.gormDB} + hasher := &hash.PoseidonHasher{} + db := storage.NewSqlStorage(provider, "test_1", hasher) + mt, err := NewMerkleTree(db, 64) assert.NoError(s.T(), err) x, _ := new(big.Int).SetString("9198063289874244593808956064764348354864043212453245695133881114917754098693", 10) @@ -104,12 +107,12 @@ func (s *MerkleTreeTestSuite) TestAddNode() { Y: y, } salt1, _ := new(big.Int).SetString("43c49e8ba68a9b8a6bb5c230a734d8271a83d2f63722e7651272ebeef5446e", 16) - utxo1 := node.NewFungible(big.NewInt(10), alice, salt1) + utxo1 := node.NewFungible(big.NewInt(10), alice, salt1, hasher) idx1, err := utxo1.CalculateIndex() assert.NoError(s.T(), err) assert.Equal(s.T(), "11a22e32f5010d3658d1da9c93f26b77afe7a84346f49eae3d1d4fc6cd0a36fd", idx1.BigInt().Text(16)) - n1, err := node.NewLeafNode(utxo1) + n1, err := node.NewLeafNode(utxo1, nil) assert.NoError(s.T(), err) err = mt.AddLeaf(n1) assert.NoError(s.T(), err) @@ -117,11 +120,11 @@ func (s *MerkleTreeTestSuite) TestAddNode() { // adding a 2nd node to test the tree update and branch nodes salt2, _ := new(big.Int).SetString("19b965f7629e4f0c4bd0b8f9c87f17580f18a32a31b4641550071ee4916bbbfc", 16) - utxo2 := node.NewFungible(big.NewInt(20), alice, salt2) + utxo2 := node.NewFungible(big.NewInt(20), alice, salt2, hasher) idx2, err := utxo2.CalculateIndex() assert.NoError(s.T(), err) assert.Equal(s.T(), "197b0dc3f167041e03d3eafacec1aa3ab12a0d7a606581af01447c269935e521", idx2.BigInt().Text(16)) - n2, err := node.NewLeafNode(utxo2) + n2, err := node.NewLeafNode(utxo2, nil) assert.NoError(s.T(), err) err = mt.AddLeaf(n2) assert.NoError(s.T(), err) @@ -129,11 +132,11 @@ func (s *MerkleTreeTestSuite) TestAddNode() { // adding a 3rd node to test the tree update and branch nodes with a left/right child node salt3, _ := new(big.Int).SetString("9b0b93df975547e430eabff085a77831b8fcb6b5396e6bb815fda8d14125370", 16) - utxo3 := node.NewFungible(big.NewInt(30), alice, salt3) + utxo3 := node.NewFungible(big.NewInt(30), alice, salt3, hasher) idx3, err := utxo3.CalculateIndex() assert.NoError(s.T(), err) assert.Equal(s.T(), "2d46e23e813abf1fdabffe3ff22a38ebf6bb92d7c381463bee666eb010289fd5", idx3.BigInt().Text(16)) - n3, err := node.NewLeafNode(utxo3) + n3, err := node.NewLeafNode(utxo3, nil) assert.NoError(s.T(), err) err = mt.AddLeaf(n3) assert.NoError(s.T(), err) @@ -141,11 +144,11 @@ func (s *MerkleTreeTestSuite) TestAddNode() { // adding a 4th node to test the tree update and branch nodes with the other left/right child node salt4, _ := new(big.Int).SetString("194ec10ec96a507c7c9b60df133d13679b874b0bd6ab89920135508f55b3f064", 16) - utxo4 := node.NewFungible(big.NewInt(40), alice, salt4) + utxo4 := node.NewFungible(big.NewInt(40), alice, salt4, hasher) idx4, err := utxo4.CalculateIndex() assert.NoError(s.T(), err) assert.Equal(s.T(), "887884c3421b72f8f1991c64808262da78732abf961118d02b0792bd421521f", idx4.BigInt().Text(16)) - n4, err := node.NewLeafNode(utxo4) + n4, err := node.NewLeafNode(utxo4, nil) assert.NoError(s.T(), err) err = mt.AddLeaf(n4) assert.NoError(s.T(), err) @@ -161,17 +164,130 @@ func (s *MerkleTreeTestSuite) TestAddNode() { assert.Equal(s.T(), n1.Index().Hex(), dbNode1.Index().Hex()) // test storage persistence across tree creation - mt2, err := NewMerkleTree(s.db, 10) + mt2, err := NewMerkleTree(db, 10) assert.NoError(s.T(), err) assert.Equal(s.T(), "abacf46f5217552ee28fe50b8fd7ca6aa46daeb9acf9f60928654c3b1a472f23", mt2.Root().Hex()) } +// cross-referenced with the unit tests in iden3/js-merkletree repo +func (s *MerkleTreeTestSuite) TestAddNode_Keccak256_TwoNodes() { + provider := &testSqlProvider{db: s.gormDB} + hasher := &hash.Keccak256Hasher{} + db := storage.NewSqlStorage(provider, "test_1", hasher) + mt, err := NewMerkleTree(db, 64) + assert.NoError(s.T(), err) + + // adding first node: i=1, v=2 + i1, _ := node.NewNodeIndexFromBigInt(big.NewInt(1), hasher) + inode1 := utils.NewIndexOnly(i1) + v1 := big.NewInt(2) + n1, err := node.NewLeafNode(inode1, v1) + assert.NoError(s.T(), err) + + err = mt.AddLeaf(n1) + assert.NoError(s.T(), err) + assert.Equal(s.T(), "2d163ec3852e4a9110862823eb833344b6e15bc64b3e415d5634f5dc79a8fd2c", mt.Root().Hex()) + assert.Equal(s.T(), "20349940423862035287868699599764962454537984981628200184279725786303353984557", mt.Root().BigInt().Text(10)) + + // adding second node: i=33, v=44 + i2, _ := node.NewNodeIndexFromBigInt(big.NewInt(33), hasher) + inode2 := utils.NewIndexOnly(i2) + v2 := big.NewInt(44) + n2_, err := node.NewLeafNode(inode2, v2) + assert.NoError(s.T(), err) + + err = mt.AddLeaf(n2_) + assert.NoError(s.T(), err) + assert.Equal(s.T(), "621b0f04a6486a2e9205ee837635daecd0feeb7409ad42f9a5f00cdf82c934a9", mt.Root().Hex()) + assert.Equal(s.T(), "76534138237239231515859035502772486263463178175980489503663557460094727691106", mt.Root().BigInt().Text(10)) +} + +func (s *MerkleTreeTestSuite) TestAddNode_Keccak256() { + provider := &testSqlProvider{db: s.gormDB} + hasher := &hash.Keccak256Hasher{} + db := storage.NewSqlStorage(provider, "test_1", hasher) + mt, err := NewMerkleTree(db, 64) + assert.NoError(s.T(), err) + + x, _ := new(big.Int).SetString("9198063289874244593808956064764348354864043212453245695133881114917754098693", 10) + y, _ := new(big.Int).SetString("3600411115173311692823743444460566395943576560299970643507632418781961416843", 10) + alice := &babyjub.PublicKey{ + X: x, + Y: y, + } + salt1, _ := new(big.Int).SetString("43c49e8ba68a9b8a6bb5c230a734d8271a83d2f63722e7651272ebeef5446e", 16) + utxo1 := node.NewFungible(big.NewInt(10), alice, salt1, hasher) + idx1, err := utxo1.CalculateIndex() + assert.NoError(s.T(), err) + assert.Equal(s.T(), "7760ce7c5a1b6b61e0647d46e52981efea01f53312d061ae7ad3c83d890e7843", idx1.BigInt().Text(16)) + + n1, err := node.NewLeafNode(utxo1, nil) + assert.NoError(s.T(), err) + err = mt.AddLeaf(n1) + assert.NoError(s.T(), err) + assert.Equal(s.T(), "a82f5e2badeb0e558f3e198f2ab1d55eb2134d90d7d886f901c70b859fa24f59", mt.Root().Hex()) + assert.Equal(s.T(), "40396546825579280798065248979086627653929672915398237421353407506268343381928", mt.Root().BigInt().Text(10)) + + // adding a 2nd node to test the tree update and branch nodes + salt2, _ := new(big.Int).SetString("19b965f7629e4f0c4bd0b8f9c87f17580f18a32a31b4641550071ee4916bbbfc", 16) + utxo2 := node.NewFungible(big.NewInt(20), alice, salt2, hasher) + idx2, err := utxo2.CalculateIndex() + assert.NoError(s.T(), err) + assert.Equal(s.T(), "1853944f79b4386d0b7a71243d19fb40a90484e0bc8a050b5f6b036a28fc221a", idx2.BigInt().Text(16)) + n2, err := node.NewLeafNode(utxo2, nil) + assert.NoError(s.T(), err) + err = mt.AddLeaf(n2) + assert.NoError(s.T(), err) + assert.Equal(s.T(), "9de0daf77df872b087e07547e6d9a8ee87a4f35200638dc58ddbe7615c9a8e40", mt.Root().Hex()) + + // adding a 3rd node to test the tree update and branch nodes with a left/right child node + salt3, _ := new(big.Int).SetString("9b0b93df975547e430eabff085a77831b8fcb6b5396e6bb815fda8d14125370", 16) + utxo3 := node.NewFungible(big.NewInt(30), alice, salt3, hasher) + idx3, err := utxo3.CalculateIndex() + assert.NoError(s.T(), err) + assert.Equal(s.T(), "8e75e5af39d302122a2b48fa75f666843a9c46b3f0c720d3e503280f22947539", idx3.BigInt().Text(16)) + n3, err := node.NewLeafNode(utxo3, nil) + assert.NoError(s.T(), err) + err = mt.AddLeaf(n3) + assert.NoError(s.T(), err) + assert.Equal(s.T(), "194b5df5301abc8a78c1beacf5c6517b33471da0b44a0acbcf54f12e969d9ec2", mt.Root().Hex()) + + // adding a 4th node to test the tree update and branch nodes with the other left/right child node + salt4, _ := new(big.Int).SetString("194ec10ec96a507c7c9b60df133d13679b874b0bd6ab89920135508f55b3f064", 16) + utxo4 := node.NewFungible(big.NewInt(40), alice, salt4, hasher) + idx4, err := utxo4.CalculateIndex() + assert.NoError(s.T(), err) + assert.Equal(s.T(), "f073e8fe1328a3b8047915a093ecbffba905d20960f43bddb85ec7eb73ea318b", idx4.BigInt().Text(16)) + n4, err := node.NewLeafNode(utxo4, nil) + assert.NoError(s.T(), err) + err = mt.AddLeaf(n4) + assert.NoError(s.T(), err) + assert.Equal(s.T(), "31173b6eccce929ada2c71e408361502fc71981c8d04e1230d0ecf1888ad5949", mt.Root().Hex()) + + // test storage persistence + rawDB := mt.(*sparseMerkleTree).db + rootIdx, err := rawDB.GetRootNodeRef() + assert.NoError(s.T(), err) + assert.Equal(s.T(), "31173b6eccce929ada2c71e408361502fc71981c8d04e1230d0ecf1888ad5949", rootIdx.Hex()) + dbNode1, err := rawDB.GetNode(n1.Ref()) + assert.NoError(s.T(), err) + assert.Equal(s.T(), n1.Index().Hex(), dbNode1.Index().Hex()) + + // test storage persistence across tree creation + mt2, err := NewMerkleTree(db, 10) + assert.NoError(s.T(), err) + assert.Equal(s.T(), "31173b6eccce929ada2c71e408361502fc71981c8d04e1230d0ecf1888ad5949", mt2.Root().Hex()) +} + func (s *MerkleTreeTestSuite) TestAddNodeWithValue() { - mt, err := NewMerkleTree(s.db, 64) + provider := &testSqlProvider{db: s.gormDB} + hasher := &hash.PoseidonHasher{} + db := storage.NewSqlStorage(provider, "test_1", hasher) + mt, err := NewMerkleTree(db, 64) assert.NoError(s.T(), err) num1, _ := new(big.Int).SetString("2096622280825605732680813932752245818650977932351778776082900098091126550803", 10) - idx1, _ := node.NewNodeIndexFromBigInt(num1) + idx1, _ := node.NewNodeIndexFromBigInt(num1, hasher) i1 := utils.NewIndexOnly(idx1) value, _ := new(big.Int).SetString("103929005307130220006098923584552504982110632080", 10) node1, _ := node.NewLeafNode(i1, value) @@ -181,7 +297,7 @@ func (s *MerkleTreeTestSuite) TestAddNodeWithValue() { assert.Equal(s.T(), "30217116944257091399475853416903058458458941628960743326838300308858186421", mt.Root().BigInt().Text(10)) num2, _ := new(big.Int).SetString("15090204826491664659381707037550246536226753383907517787209741376692915222845", 10) - idx2, _ := node.NewNodeIndexFromBigInt(num2) + idx2, _ := node.NewNodeIndexFromBigInt(num2, hasher) i2 := utils.NewIndexOnly(idx2) value2, _ := new(big.Int).SetString("103929005307130220006098923584552504982110632080", 10) node2, _ := node.NewLeafNode(i2, value2) @@ -191,8 +307,39 @@ func (s *MerkleTreeTestSuite) TestAddNodeWithValue() { assert.Equal(s.T(), "13510168183919975355906555974433619775354581939566212907435695290053458902080", mt.Root().BigInt().Text(10)) } +func (s *MerkleTreeTestSuite) TestAddNodeWithValue_Keccak256() { + provider := &testSqlProvider{db: s.gormDB} + hasher := &hash.Keccak256Hasher{} + db := storage.NewSqlStorage(provider, "test_1", hasher) + mt, err := NewMerkleTree(db, 64) + assert.NoError(s.T(), err) + + num1, _ := new(big.Int).SetString("2096622280825605732680813932752245818650977932351778776082900098091126550803", 10) + idx1, _ := node.NewNodeIndexFromBigInt(num1, hasher) + i1 := utils.NewIndexOnly(idx1) + value, _ := new(big.Int).SetString("103929005307130220006098923584552504982110632080", 10) + node1, _ := node.NewLeafNode(i1, value) + + err = mt.AddLeaf(node1) + assert.NoError(s.T(), err) + assert.Equal(s.T(), "82804925767799109303590842121762391552430492588263699753375838529512360846329", mt.Root().BigInt().Text(10)) + + num2, _ := new(big.Int).SetString("15090204826491664659381707037550246536226753383907517787209741376692915222845", 10) + idx2, _ := node.NewNodeIndexFromBigInt(num2, hasher) + i2 := utils.NewIndexOnly(idx2) + value2, _ := new(big.Int).SetString("103929005307130220006098923584552504982110632080", 10) + node2, _ := node.NewLeafNode(i2, value2) + + err = mt.AddLeaf(node2) + assert.NoError(s.T(), err) + assert.Equal(s.T(), "89791312731002442049339692978860823183831246235876919306102714467446488917251", mt.Root().BigInt().Text(10)) +} + func (s *MerkleTreeTestSuite) TestAddNodeFailExistingKey() { - mt, err := NewMerkleTree(s.db, 64) + provider := &testSqlProvider{db: s.gormDB} + hasher := &hash.PoseidonHasher{} + db := storage.NewSqlStorage(provider, "test_1", hasher) + mt, err := NewMerkleTree(db, 64) assert.NoError(s.T(), err) x, _ := new(big.Int).SetString("9198063289874244593808956064764348354864043212453245695133881114917754098693", 10) @@ -202,12 +349,12 @@ func (s *MerkleTreeTestSuite) TestAddNodeFailExistingKey() { Y: y, } salt1, _ := new(big.Int).SetString("43c49e8ba68a9b8a6bb5c230a734d8271a83d2f63722e7651272ebeef5446e", 16) - utxo1 := node.NewFungible(big.NewInt(10), alice, salt1) + utxo1 := node.NewFungible(big.NewInt(10), alice, salt1, hasher) idx1, err := utxo1.CalculateIndex() assert.NoError(s.T(), err) assert.Equal(s.T(), "11a22e32f5010d3658d1da9c93f26b77afe7a84346f49eae3d1d4fc6cd0a36fd", idx1.BigInt().Text(16)) - n1, err := node.NewLeafNode(utxo1) + n1, err := node.NewLeafNode(utxo1, nil) assert.NoError(s.T(), err) err = mt.AddLeaf(n1) assert.NoError(s.T(), err) @@ -219,25 +366,28 @@ func (s *MerkleTreeTestSuite) TestAddNodeFailExistingKey() { func (s *MerkleTreeTestSuite) TestGenerateProof() { const levels = 64 - mt, _ := NewMerkleTree(s.db, levels) + provider := &testSqlProvider{db: s.gormDB} + hasher := &hash.PoseidonHasher{} + db := storage.NewSqlStorage(provider, "test_1", hasher) + mt, _ := NewMerkleTree(db, levels) alice := testutils.NewKeypair() - utxo1 := node.NewFungible(big.NewInt(10), alice.PublicKey, big.NewInt(12345)) - node1, err := node.NewLeafNode(utxo1) + utxo1 := node.NewFungible(big.NewInt(10), alice.PublicKey, big.NewInt(12345), hasher) + node1, err := node.NewLeafNode(utxo1, nil) assert.NoError(s.T(), err) err = mt.AddLeaf(node1) assert.NoError(s.T(), err) - utxo2 := node.NewFungible(big.NewInt(10), alice.PublicKey, big.NewInt(12346)) - node2, err := node.NewLeafNode(utxo2) + utxo2 := node.NewFungible(big.NewInt(10), alice.PublicKey, big.NewInt(12346), hasher) + node2, err := node.NewLeafNode(utxo2, nil) assert.NoError(s.T(), err) err = mt.AddLeaf(node2) assert.NoError(s.T(), err) target1 := node1.Index().BigInt() - utxo3 := node.NewFungible(big.NewInt(10), alice.PublicKey, big.NewInt(12347)) - node3, err := node.NewLeafNode(utxo3) + utxo3 := node.NewFungible(big.NewInt(10), alice.PublicKey, big.NewInt(12347), hasher) + node3, err := node.NewLeafNode(utxo3, nil) assert.NoError(s.T(), err) target2 := node3.Index().BigInt() proofs, foundValues, err := mt.GenerateProofs([]*big.Int{target1, target2}, mt.Root()) @@ -255,7 +405,10 @@ func (s *MerkleTreeTestSuite) TestGenerateProof() { func (s *MerkleTreeTestSuite) TestGenerateProofWithValue() { const levels = 64 - mt, _ := NewMerkleTree(s.db, levels) + provider := &testSqlProvider{db: s.gormDB} + hasher := &hash.PoseidonHasher{} + db := storage.NewSqlStorage(provider, "test_1", hasher) + mt, _ := NewMerkleTree(db, levels) x, _ := new(big.Int).SetString("5942093613500723806297813179240005997319949155197126751651583942828687054842", 10) y, _ := new(big.Int).SetString("2705857439293983766697920596184407125756255052151793307734211470588083660177", 10) @@ -267,14 +420,14 @@ func (s *MerkleTreeTestSuite) TestGenerateProofWithValue() { value, _ := new(big.Int).SetString("103929005307130220006098923584552504982110632080", 10) - utxo1 := node.NewFungible(big.NewInt(15), alice, salt1) + utxo1 := node.NewFungible(big.NewInt(15), alice, salt1, hasher) node1, err := node.NewLeafNode(utxo1, value) assert.NoError(s.T(), err) err = mt.AddLeaf(node1) assert.NoError(s.T(), err) salt2, _ := new(big.Int).SetString("20958393090813127612863788731259135207417921338630643176495259330913242296380", 10) - utxo2 := node.NewFungible(big.NewInt(100), alice, salt2) + utxo2 := node.NewFungible(big.NewInt(100), alice, salt2, hasher) node2, err := node.NewLeafNode(utxo2, value) assert.NoError(s.T(), err) err = mt.AddLeaf(node2) @@ -301,7 +454,10 @@ func (s *MerkleTreeTestSuite) TestGenerateProofWithValue() { func (s *MerkleTreeTestSuite) TestVerifyProof() { const levels = 100 - mt, _ := NewMerkleTree(s.db, levels) + provider := &testSqlProvider{db: s.gormDB} + hasher := &hash.PoseidonHasher{} + db := storage.NewSqlStorage(provider, "test_1", hasher) + mt, _ := NewMerkleTree(db, levels) alice := testutils.NewKeypair() values := []int{10, 20, 30, 40, 50, 60, 70, 80, 90, 100} @@ -310,8 +466,8 @@ func (s *MerkleTreeTestSuite) TestVerifyProof() { for idx, value := range values { go func(v int, idx int) { salt := rand.Intn(100000) - utxo := node.NewFungible(big.NewInt(int64(v)), alice.PublicKey, big.NewInt(int64(salt))) - node, err := node.NewLeafNode(utxo) + utxo := node.NewFungible(big.NewInt(int64(v)), alice.PublicKey, big.NewInt(int64(salt)), hasher) + node, err := node.NewLeafNode(utxo, nil) assert.NoError(s.T(), err) err = mt.AddLeaf(node) assert.NoError(s.T(), err) @@ -343,7 +499,10 @@ func (s *MerkleTreeTestSuite) TestVerifyProof() { } func (s *MerkleTreeTestSuite) TestSqliteStorage() { - mt, err := NewMerkleTree(s.db, 64) + provider := &testSqlProvider{db: s.gormDB} + hasher := &hash.PoseidonHasher{} + db := storage.NewSqlStorage(provider, "test_1", hasher) + mt, err := NewMerkleTree(db, 64) assert.NoError(s.T(), err) assert.NotNil(s.T(), mt) @@ -353,8 +512,8 @@ func (s *MerkleTreeTestSuite) 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) diff --git a/go-sdk/internal/sparse-merkle-tree/storage/sql.go b/go-sdk/internal/sparse-merkle-tree/storage/sql.go index f3ac047b..3cd34c40 100644 --- a/go-sdk/internal/sparse-merkle-tree/storage/sql.go +++ b/go-sdk/internal/sparse-merkle-tree/storage/sql.go @@ -22,6 +22,7 @@ import ( "github.com/hyperledger-labs/zeto/go-sdk/internal/sparse-merkle-tree/node" "github.com/hyperledger-labs/zeto/go-sdk/internal/sparse-merkle-tree/utils" "github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/core" + apicore "github.com/hyperledger-labs/zeto/go-sdk/pkg/utxo/core" "gorm.io/gorm" "gorm.io/gorm/clause" ) @@ -30,16 +31,18 @@ type sqlStorage struct { p core.SqlDBProvider smtName string nodesTableName string + hasher apicore.Hasher } // NewSqlStorage creates a new sqlStorage instance // The "smtName" is the name for the tree instance, it must // be unique within the backend database instance -func NewSqlStorage(p core.SqlDBProvider, smtName string) *sqlStorage { +func NewSqlStorage(p core.SqlDBProvider, smtName string, hasher apicore.Hasher) *sqlStorage { return &sqlStorage{ p: p, smtName: smtName, nodesTableName: core.NodesTablePrefix + smtName, + hasher: hasher, } } @@ -53,7 +56,7 @@ func (s *sqlStorage) GetRootNodeRef() (core.NodeRef, error) { } else if err != nil { return nil, err } - idx, err := node.NewNodeIndexFromHex(root.RootRef) + idx, err := node.NewNodeIndexFromHex(root.RootRef, s.hasher) return idx, err } @@ -62,7 +65,7 @@ func (s *sqlStorage) UpsertRootNodeRef(root core.NodeRef) error { } func (s *sqlStorage) GetNode(ref core.NodeRef) (core.Node, error) { - return getNode(s.p.DB(), s.nodesTableName, ref) + return getNode(s.p.DB(), s.nodesTableName, ref, s.hasher) } func (s *sqlStorage) InsertNode(n core.Node) error { @@ -81,6 +84,7 @@ type sqlTxStorage struct { tx *gorm.DB smtName string nodesTableName string + hasher apicore.Hasher } func (b *sqlTxStorage) UpsertRootNodeRef(root core.NodeRef) error { @@ -88,7 +92,7 @@ func (b *sqlTxStorage) UpsertRootNodeRef(root core.NodeRef) error { } func (b *sqlTxStorage) GetNode(ref core.NodeRef) (core.Node, error) { - return getNode(b.tx, b.nodesTableName, ref) + return getNode(b.tx, b.nodesTableName, ref, b.hasher) } func (b *sqlTxStorage) InsertNode(n core.Node) error { @@ -107,6 +111,10 @@ func (m *sqlStorage) Close() { m.p.Close() } +func (m *sqlStorage) GetHasher() apicore.Hasher { + return m.hasher +} + func upsertRootNodeRef(batchOrDb *gorm.DB, name string, root core.NodeRef) error { err := batchOrDb.Table(core.TreeRootsTable).Save(&core.SMTRoot{ RootRef: root.Hex(), @@ -115,7 +123,7 @@ func upsertRootNodeRef(batchOrDb *gorm.DB, name string, root core.NodeRef) error return err } -func getNode(batchOrDb *gorm.DB, nodesTableName string, ref core.NodeRef) (core.Node, error) { +func getNode(batchOrDb *gorm.DB, nodesTableName string, ref core.NodeRef, hasher apicore.Hasher) (core.Node, error) { // the node's reference key (not the index) is used as the key to // store the node in the DB n := core.SMTNode{ @@ -131,7 +139,7 @@ func getNode(batchOrDb *gorm.DB, nodesTableName string, ref core.NodeRef) (core. nodeType := core.NodeTypeFromByte(n.Type) switch nodeType { case core.NodeTypeLeaf: - idx, err1 := node.NewNodeIndexFromHex(*n.Index) + idx, err1 := node.NewNodeIndexFromHex(*n.Index, hasher) if err1 != nil { return nil, err1 } @@ -143,18 +151,18 @@ func getNode(batchOrDb *gorm.DB, nodesTableName string, ref core.NodeRef) (core. } newNode, err = node.NewLeafNode(index, value) } else { - newNode, err = node.NewLeafNode(index) + newNode, err = node.NewLeafNode(index, nil) } case core.NodeTypeBranch: - leftChild, err1 := node.NewNodeIndexFromHex(*n.LeftChild) + leftChild, err1 := node.NewNodeIndexFromHex(*n.LeftChild, hasher) if err1 != nil { return nil, err1 } - rightChild, err2 := node.NewNodeIndexFromHex(*n.RightChild) + rightChild, err2 := node.NewNodeIndexFromHex(*n.RightChild, hasher) if err2 != nil { return nil, err2 } - newNode, err = node.NewBranchNode(leftChild, rightChild) + newNode, err = node.NewBranchNode(leftChild, rightChild, hasher) } return newNode, err } diff --git a/go-sdk/internal/sparse-merkle-tree/storage/sql_test.go b/go-sdk/internal/sparse-merkle-tree/storage/sql_test.go index ce684738..4a206f61 100644 --- a/go-sdk/internal/sparse-merkle-tree/storage/sql_test.go +++ b/go-sdk/internal/sparse-merkle-tree/storage/sql_test.go @@ -22,6 +22,7 @@ import ( "testing" "github.com/hyperledger-labs/zeto/go-sdk/internal/crypto" + "github.com/hyperledger-labs/zeto/go-sdk/internal/crypto/hash" "github.com/hyperledger-labs/zeto/go-sdk/internal/sparse-merkle-tree/node" "github.com/hyperledger-labs/zeto/go-sdk/internal/testutils" "github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/core" @@ -54,7 +55,7 @@ func TestSqliteStorage(t *testing.T) { assert.NoError(t, err) provider := &testSqlProvider{db: db} - s := NewSqlStorage(provider, "test_1") + s := NewSqlStorage(provider, "test_1", &hash.PoseidonHasher{}) assert.NoError(t, err) tokenId := big.NewInt(1001) @@ -63,8 +64,8 @@ func TestSqliteStorage(t *testing.T) { 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, &hash.PoseidonHasher{}) + n1, err := node.NewLeafNode(utxo1, nil) assert.NoError(t, err) idx, _ := utxo1.CalculateIndex() @@ -91,7 +92,7 @@ func TestSqliteStorage(t *testing.T) { assert.NoError(t, err) assert.Equal(t, n1.Ref().Hex(), n2.Ref().Hex()) - bn1, err := node.NewBranchNode(n1.Ref(), n1.Ref()) + bn1, err := node.NewBranchNode(n1.Ref(), n1.Ref(), &hash.PoseidonHasher{}) assert.NoError(t, err) err = s.InsertNode(bn1) assert.NoError(t, err) @@ -111,7 +112,7 @@ func TestSqliteStorageFail_NoRootTable(t *testing.T) { assert.NoError(t, err) provider := &testSqlProvider{db: db} - s := NewSqlStorage(provider, "test_1") + s := NewSqlStorage(provider, "test_1", &hash.PoseidonHasher{}) assert.NoError(t, err) _, err = s.GetRootNodeRef() @@ -134,10 +135,10 @@ func TestSqliteStorageFail_NoNodeTable(t *testing.T) { assert.NoError(t, err) provider := &testSqlProvider{db: db} - s := NewSqlStorage(provider, "test_1") + s := NewSqlStorage(provider, "test_1", &hash.PoseidonHasher{}) assert.NoError(t, err) - idx, err := node.NewNodeIndexFromHex("0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef") + idx, err := node.NewNodeIndexFromHex("0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", &hash.PoseidonHasher{}) assert.NoError(t, err) _, err = s.GetNode(idx) assert.EqualError(t, err, "no such table: smtNodes_test_1") @@ -163,14 +164,14 @@ func TestSqliteStorageFail_BadNodeIndex(t *testing.T) { assert.NoError(t, err) provider := &testSqlProvider{db: db} - s := NewSqlStorage(provider, "test_1") + s := NewSqlStorage(provider, "test_1", &hash.PoseidonHasher{}) assert.NoError(t, err) sender := testutils.NewKeypair() salt1 := crypto.NewSalt() - utxo1 := node.NewFungible(big.NewInt(100), sender.PublicKey, salt1) - n1, err := node.NewLeafNode(utxo1) + utxo1 := node.NewFungible(big.NewInt(100), sender.PublicKey, salt1, &hash.PoseidonHasher{}) + n1, err := node.NewLeafNode(utxo1, nil) assert.NoError(t, err) err = s.InsertNode(n1) assert.NoError(t, err) @@ -187,7 +188,7 @@ func TestSqliteStorageFail_BadNodeIndex(t *testing.T) { _, err = s.GetNode(n1.Ref()) assert.EqualError(t, err, "expected 32 bytes for the decoded node index") - bn1, err := node.NewBranchNode(n1.Ref(), n1.Ref()) + bn1, err := node.NewBranchNode(n1.Ref(), n1.Ref(), &hash.PoseidonHasher{}) assert.NoError(t, err) err = s.InsertNode(bn1) assert.NoError(t, err) diff --git a/go-sdk/internal/sparse-merkle-tree/utils/indexonly.go b/go-sdk/internal/sparse-merkle-tree/utils/indexonly.go index 9be7c579..937dab33 100644 --- a/go-sdk/internal/sparse-merkle-tree/utils/indexonly.go +++ b/go-sdk/internal/sparse-merkle-tree/utils/indexonly.go @@ -18,6 +18,7 @@ package utils import ( "github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/core" + apicore "github.com/hyperledger-labs/zeto/go-sdk/pkg/utxo/core" ) type IndexOnly struct { @@ -33,3 +34,7 @@ func NewIndexOnly(index core.NodeIndex) *IndexOnly { func (f *IndexOnly) CalculateIndex() (core.NodeIndex, error) { return f.Index, nil } + +func (f *IndexOnly) GetHasher() apicore.Hasher { + return f.Index.GetHasher() +} diff --git a/go-sdk/internal/util/util.go b/go-sdk/internal/util/util.go index a027600e..55dd052c 100644 --- a/go-sdk/internal/util/util.go +++ b/go-sdk/internal/util/util.go @@ -1,17 +1,18 @@ package util import ( + "encoding/json" "fmt" "math/big" - "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/hyperledger/firefly-signer/pkg/abi" "github.com/iden3/go-rapidsnark/types" ) type EncodedProof struct { - PA [2]*big.Int `abi:"pA"` - PB [2][2]*big.Int `abi:"pB"` - PC [2]*big.Int `abi:"pC"` + PA [2]string `json:"pA"` + PB [2][2]string `json:"pB"` + PC [2]string `json:"pC"` } // EncodeProofToBytes encodes the ZKProof to bytes for contract interaction @@ -20,13 +21,17 @@ func EncodeToBytes_Anon(proof *types.ProofData) ([]byte, error) { if err != nil { return nil, err } + jsonObj := map[string]interface{}{ + "proof": proofStruct, + } + proofJSONBytes, _ := json.Marshal(jsonObj) // Create the ABI type with explicit components using shared function proofType := createProofType() // Use abi.Arguments to pack the data - arguments := abi.Arguments{abi.Argument{Type: proofType}} - proofBytes, err := arguments.Pack(proofStruct) + arguments := abi.ParameterArray{proofType} + proofBytes, err := arguments.EncodeABIDataJSON(proofJSONBytes) if err != nil { return nil, err } @@ -39,18 +44,20 @@ func EncodeToBytes_Nullifier(root *big.Int, proof *types.ProofData) ([]byte, err if err != nil { return nil, err } + jsonObj := map[string]interface{}{ + "root": "0x" + root.Text(16), + "proof": proofStruct, + } + proofJSONBytes, _ := json.Marshal(jsonObj) // Create ABI types for each parameter using shared functions - rootType := createUint256Type() + rootType := createUint256Type("root") proofType := createProofType() // Pack the data using ABI encoding (matching TypeScript parameter order) - arguments := abi.Arguments{ - abi.Argument{Type: rootType}, - abi.Argument{Type: proofType}, - } + arguments := abi.ParameterArray{rootType, proofType} - proofBytes, err := arguments.Pack(root, proofStruct) + proofBytes, err := arguments.EncodeABIDataJSON(proofJSONBytes) if err != nil { return nil, err } @@ -63,22 +70,35 @@ func EncodeToBytes_Enc(encryptionNonce *big.Int, ecdhPublicKey [2]*big.Int, encr if err != nil { return nil, err } + jsonObj := map[string]interface{}{ + "encryptionNonce": "0x" + encryptionNonce.Text(16), + "ecdhPublicKey": [2]string{"0x" + ecdhPublicKey[0].Text(16), "0x" + ecdhPublicKey[1].Text(16)}, + "encryptedValues": func() []string { + values := make([]string, len(encryptedValues)) + for i, v := range encryptedValues { + values[i] = "0x" + v.Text(16) + } + return values + }(), + "proof": proofStruct, + } + proofJSONBytes, _ := json.Marshal(jsonObj) // Create ABI types for each parameter using shared functions - encryptionNonceType := createUint256Type() - ecdhPublicKeyType := createUint256Array2Type() - encryptedValuesType := createUint256ArrayType() + encryptionNonceType := createUint256Type("encryptionNonce") + ecdhPublicKeyType := createUint256Array2Type("ecdhPublicKey") + encryptedValuesType := createUint256ArrayType("encryptedValues") proofType := createProofType() // Pack the data using ABI encoding (matching TypeScript parameter order) - arguments := abi.Arguments{ - abi.Argument{Type: encryptionNonceType}, - abi.Argument{Type: ecdhPublicKeyType}, - abi.Argument{Type: encryptedValuesType}, - abi.Argument{Type: proofType}, + arguments := abi.ParameterArray{ + encryptionNonceType, + ecdhPublicKeyType, + encryptedValuesType, + proofType, } - proofBytes, err := arguments.Pack(encryptionNonce, ecdhPublicKey, encryptedValues, proofStruct) + proofBytes, err := arguments.EncodeABIDataJSON(proofJSONBytes) if err != nil { return nil, err } @@ -91,24 +111,38 @@ func EncodeToBytes_EncNullifier(root, encryptionNonce *big.Int, ecdhPublicKey [2 if err != nil { return nil, err } + jsonObj := map[string]interface{}{ + "root": "0x" + root.Text(16), + "encryptionNonce": "0x" + encryptionNonce.Text(16), + "ecdhPublicKey": [2]string{"0x" + ecdhPublicKey[0].Text(16), "0x" + ecdhPublicKey[1].Text(16)}, + "encryptedValues": func() []string { + values := make([]string, len(encryptedValues)) + for i, v := range encryptedValues { + values[i] = "0x" + v.Text(16) + } + return values + }(), + "proof": proofStruct, + } + proofJSONBytes, _ := json.Marshal(jsonObj) // Create ABI types for each parameter using shared functions - rootType := createUint256Type() - encryptionNonceType := createUint256Type() - ecdhPublicKeyType := createUint256Array2Type() - encryptedValuesType := createUint256ArrayType() + rootType := createUint256Type("root") + encryptionNonceType := createUint256Type("encryptionNonce") + ecdhPublicKeyType := createUint256Array2Type("ecdhPublicKey") + encryptedValuesType := createUint256ArrayType("encryptedValues") proofType := createProofType() // Pack the data using ABI encoding (matching TypeScript parameter order) - arguments := abi.Arguments{ - abi.Argument{Type: rootType}, - abi.Argument{Type: encryptionNonceType}, - abi.Argument{Type: ecdhPublicKeyType}, - abi.Argument{Type: encryptedValuesType}, - abi.Argument{Type: proofType}, + arguments := abi.ParameterArray{ + rootType, + encryptionNonceType, + ecdhPublicKeyType, + encryptedValuesType, + proofType, } - proofBytes, err := arguments.Pack(root, encryptionNonce, ecdhPublicKey, encryptedValues, proofStruct) + proofBytes, err := arguments.EncodeABIDataJSON(proofJSONBytes) if err != nil { return nil, err } @@ -121,26 +155,47 @@ func EncodeToBytes_EncNullifierNonRepudiation(root, encryptionNonce *big.Int, ec if err != nil { return nil, err } + jsonObj := map[string]interface{}{ + "root": "0x" + root.Text(16), + "encryptionNonce": "0x" + encryptionNonce.Text(16), + "ecdhPublicKey": [2]string{"0x" + ecdhPublicKey[0].Text(16), "0x" + ecdhPublicKey[1].Text(16)}, + "encryptedValuesForReceiver": func() []string { + values := make([]string, len(encryptedValuesForReceiver)) + for i, v := range encryptedValuesForReceiver { + values[i] = "0x" + v.Text(16) + } + return values + }(), + "encryptedValuesForAuthority": func() []string { + values := make([]string, len(encryptedValuesForAuthority)) + for i, v := range encryptedValuesForAuthority { + values[i] = "0x" + v.Text(16) + } + return values + }(), + "proof": proofStruct, + } + proofJSONBytes, _ := json.Marshal(jsonObj) // Create ABI types for each parameter using shared functions - rootType := createUint256Type() - encryptionNonceType := createUint256Type() - ecdhPublicKeyType := createUint256Array2Type() - encryptedValuesForReceiverType := createUint256ArrayType() - encryptedValuesForAuthorityType := createUint256ArrayType() + rootType := createUint256Type("root") + encryptionNonceType := createUint256Type("encryptionNonce") + ecdhPublicKeyType := createUint256Array2Type("ecdhPublicKey") + encryptedValuesForReceiverType := createUint256ArrayType("encryptedValuesForReceiver") + encryptedValuesForAuthorityType := createUint256ArrayType("encryptedValuesForAuthority") proofType := createProofType() // Pack the data using ABI encoding (matching TypeScript parameter order) - arguments := abi.Arguments{ - abi.Argument{Type: rootType}, - abi.Argument{Type: encryptionNonceType}, - abi.Argument{Type: ecdhPublicKeyType}, - abi.Argument{Type: encryptedValuesForReceiverType}, - abi.Argument{Type: encryptedValuesForAuthorityType}, - abi.Argument{Type: proofType}, + arguments := abi.ParameterArray{ + rootType, + encryptionNonceType, + ecdhPublicKeyType, + encryptedValuesForReceiverType, + encryptedValuesForAuthorityType, + proofType, } - proofBytes, err := arguments.Pack(root, encryptionNonce, ecdhPublicKey, encryptedValuesForReceiver, encryptedValuesForAuthority, proofStruct) + proofBytes, err := arguments.EncodeABIDataJSON(proofJSONBytes) if err != nil { return nil, err } @@ -153,24 +208,44 @@ func EncodeToBytes_Qurrency(root *big.Int, encryptionNonce *big.Int, encryptedVa if err != nil { return nil, err } + jsonObj := map[string]interface{}{ + "root": "0x" + root.Text(16), + "encryptionNonce": "0x" + encryptionNonce.Text(16), + "encryptedValues": func() []string { + values := make([]string, len(encryptedValues)) + for i, v := range encryptedValues { + values[i] = "0x" + v.Text(16) + } + return values + }(), + "encapsulatedSharedSecret": func() []string { + values := make([]string, len(encapsulatedSharedSecret)) + for i, v := range encapsulatedSharedSecret { + values[i] = "0x" + v.Text(16) + } + return values + }(), + "proof": proofStruct, + } + proofJSONBytes, _ := json.Marshal(jsonObj) // Create ABI types for each parameter using shared functions - rootType := createUint256Type() - encryptionNonceType := createUint256Type() - encryptedValuesType := createUint256ArrayType() - encapsulatedSharedSecretType := createUint256Array25Type() + rootType := createUint256Type("root") + encryptionNonceType := createUint256Type("encryptionNonce") + encryptedValuesType := createUint256ArrayType("encryptedValues") + encapsulatedSharedSecretType := createUint256Array25Type("encapsulatedSharedSecret") proofType := createProofType() // Pack the data using ABI encoding (matching TypeScript parameter order) - arguments := abi.Arguments{ - abi.Argument{Type: rootType}, - abi.Argument{Type: encryptionNonceType}, - abi.Argument{Type: encryptedValuesType}, - abi.Argument{Type: encapsulatedSharedSecretType}, - abi.Argument{Type: proofType}, + arguments := abi.ParameterArray{ + rootType, + encryptionNonceType, + encryptedValuesType, + encapsulatedSharedSecretType, + proofType, } - proofBytes, err := arguments.Pack(root, encryptionNonce, encryptedValues, encapsulatedSharedSecret, proofStruct) + proofBytes, err := arguments.EncodeABIDataJSON(proofJSONBytes) if err != nil { return nil, err } @@ -209,48 +284,64 @@ func convertProof(proof *types.ProofData) (*EncodedProof, error) { // Create the proof struct for ABI encoding (matching TypeScript encodeProof output) proofStruct := EncodedProof{ - PA: [2]*big.Int{pA[0], pA[1]}, - PB: [2][2]*big.Int{ + PA: [2]string{"0x" + pA[0].Text(16), "0x" + pA[1].Text(16)}, + PB: [2][2]string{ // note that the order of the elements in the pB array is reversed in the contract - {pB[0][1], pB[0][0]}, - {pB[1][1], pB[1][0]}, + {"0x" + pB[0][1].Text(16), "0x" + pB[0][0].Text(16)}, + {"0x" + pB[1][1].Text(16), "0x" + pB[1][0].Text(16)}, }, - PC: [2]*big.Int{pC[0], pC[1]}, + PC: [2]string{"0x" + pC[0].Text(16), "0x" + pC[1].Text(16)}, } return &proofStruct, nil } // createProofType creates the common proof ABI type used across all encoding methods -func createProofType() abi.Type { - t, _ := abi.NewType("tuple", "", []abi.ArgumentMarshaling{ - {Name: "pA", Type: "uint256[2]"}, - {Name: "pB", Type: "uint256[2][2]"}, - {Name: "pC", Type: "uint256[2]"}, - }) +func createProofType() *abi.Parameter { + t := &abi.Parameter{ + Type: "tuple", + Name: "proof", + Components: abi.ParameterArray{ + {Name: "pA", Type: "uint256[2]"}, + {Name: "pB", Type: "uint256[2][2]"}, + {Name: "pC", Type: "uint256[2]"}, + }, + } return t } // createUint256Type creates the common uint256 ABI type -func createUint256Type() abi.Type { - t, _ := abi.NewType("uint256", "", nil) +func createUint256Type(name string) *abi.Parameter { + t := &abi.Parameter{ + Type: "uint256", + Name: name, + } return t } // createUint256ArrayType creates the common uint256[] ABI type -func createUint256ArrayType() abi.Type { - t, _ := abi.NewType("uint256[]", "", nil) +func createUint256ArrayType(name string) *abi.Parameter { + t := &abi.Parameter{ + Type: "uint256[]", + Name: name, + } return t } // createUint256Array2Type creates the common uint256[2] ABI type -func createUint256Array2Type() abi.Type { - t, _ := abi.NewType("uint256[2]", "", nil) +func createUint256Array2Type(name string) *abi.Parameter { + t := &abi.Parameter{ + Type: "uint256[2]", + Name: name, + } return t } // createUint256Array25Type creates the common uint256[25] ABI type -func createUint256Array25Type() abi.Type { - t, _ := abi.NewType("uint256[25]", "", nil) +func createUint256Array25Type(name string) *abi.Parameter { + t := &abi.Parameter{ + Type: "uint256[25]", + Name: name, + } return t } diff --git a/go-sdk/internal/util/util_test.go b/go-sdk/internal/util/util_test.go index 3b6a8b4c..c9252d4d 100644 --- a/go-sdk/internal/util/util_test.go +++ b/go-sdk/internal/util/util_test.go @@ -460,10 +460,8 @@ func TestEncodeToBytes_Anon_InvalidStringValues(t *testing.T) { C: []string{"415", "161"}, } - // This should panic due to zero value being passed to ABI encoding - assert.Panics(t, func() { - _, _ = EncodeToBytes_Anon(proof) - }, "Expected panic due to zero value from invalid string causing ABI encoding error") + _, err := EncodeToBytes_Anon(proof) + assert.ErrorContains(t, err, "FF22030: Unable to parse") } func TestEncodeToBytes_Anon_EmptyStringValues(t *testing.T) { @@ -477,10 +475,8 @@ func TestEncodeToBytes_Anon_EmptyStringValues(t *testing.T) { C: []string{"415", "161"}, } - // This should panic due to zero value being passed to ABI encoding - assert.Panics(t, func() { - _, _ = EncodeToBytes_Anon(proof) - }, "Expected panic due to zero value from empty string causing ABI encoding error") + _, err := EncodeToBytes_Anon(proof) + assert.ErrorContains(t, err, "FF22030: Unable to parse") } // Edge case tests @@ -543,10 +539,8 @@ func TestEncodeToBytes_Enc_NilBigIntValues(t *testing.T) { C: []string{"415", "161"}, } - // This should panic due to nil big.Int being passed to ABI encoding - assert.Panics(t, func() { - _, _ = EncodeToBytes_Enc(encryptionNonce, ecdhPublicKey, encryptedValues, proof) - }, "Expected panic due to nil big.Int causing ABI encoding error") + _, err := EncodeToBytes_Enc(encryptionNonce, ecdhPublicKey, encryptedValues, proof) + assert.ErrorContains(t, err, "FF22030: Unable to parse") } func TestEncodeToBytes_Qurrency_PartialEncapsulatedSharedSecret(t *testing.T) { @@ -568,10 +562,8 @@ func TestEncodeToBytes_Qurrency_PartialEncapsulatedSharedSecret(t *testing.T) { C: []string{"415", "161"}, } - // This should panic due to nil big.Int values in the array being passed to ABI encoding - assert.Panics(t, func() { - _, _ = EncodeToBytes_Qurrency(root, encryptionNonce, encryptedValues, encapsulatedSharedSecret, proof) - }, "Expected panic due to nil big.Int values in encapsulated shared secret causing ABI encoding error") + _, err := EncodeToBytes_Qurrency(root, encryptionNonce, encryptedValues, encapsulatedSharedSecret, proof) + assert.ErrorContains(t, err, "FF22030: Unable to parse") } // Tests for convertProof function directly @@ -615,6 +607,6 @@ func TestConvertProof_ZeroValues(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, proofStruct) // Should handle zero values correctly - assert.Equal(t, big.NewInt(0), proofStruct.PA[0]) - assert.Equal(t, big.NewInt(0), proofStruct.PA[1]) + assert.Equal(t, "0x0", proofStruct.PA[0]) + assert.Equal(t, "0x0", proofStruct.PA[1]) } diff --git a/go-sdk/internal/utxo/fungible.go b/go-sdk/internal/utxo/fungible.go index 48f13b7b..373fd698 100644 --- a/go-sdk/internal/utxo/fungible.go +++ b/go-sdk/internal/utxo/fungible.go @@ -21,25 +21,26 @@ import ( "github.com/hyperledger-labs/zeto/go-sdk/pkg/utxo/core" "github.com/iden3/go-iden3-crypto/babyjub" - "github.com/iden3/go-iden3-crypto/poseidon" ) type fungible struct { Amount *big.Int Owner *babyjub.PublicKey Salt *big.Int + hasher core.Hasher } -func NewFungible(amount *big.Int, owner *babyjub.PublicKey, salt *big.Int) core.UTXO { +func NewFungible(amount *big.Int, owner *babyjub.PublicKey, salt *big.Int, hasher core.Hasher) core.UTXO { return &fungible{ Amount: amount, Owner: owner, Salt: salt, + hasher: hasher, } } func (f *fungible) GetHash() (*big.Int, error) { - hash, err := poseidon.Hash([]*big.Int{f.Amount, f.Salt, f.Owner.X, f.Owner.Y}) + hash, err := f.hasher.Hash([]*big.Int{f.Amount, f.Salt, f.Owner.X, f.Owner.Y}) if err != nil { return nil, err } @@ -53,18 +54,20 @@ type fungibleNullifier struct { Amount *big.Int Owner *big.Int Salt *big.Int + hasher core.Hasher } -func NewFungibleNullifier(amount *big.Int, owner *big.Int, salt *big.Int) core.UTXO { +func NewFungibleNullifier(amount *big.Int, owner *big.Int, salt *big.Int, hasher core.Hasher) core.UTXO { return &fungibleNullifier{ Amount: amount, Owner: owner, Salt: salt, + hasher: hasher, } } func (f *fungibleNullifier) GetHash() (*big.Int, error) { - hash, err := poseidon.Hash([]*big.Int{f.Amount, f.Salt, f.Owner}) + hash, err := f.hasher.Hash([]*big.Int{f.Amount, f.Salt, f.Owner}) if err != nil { return nil, err } diff --git a/go-sdk/internal/utxo/fungible_test.go b/go-sdk/internal/utxo/fungible_test.go index e7d5d0de..b52de47c 100644 --- a/go-sdk/internal/utxo/fungible_test.go +++ b/go-sdk/internal/utxo/fungible_test.go @@ -20,6 +20,7 @@ import ( "math/big" "testing" + "github.com/hyperledger-labs/zeto/go-sdk/internal/crypto/hash" "github.com/iden3/go-iden3-crypto/babyjub" "github.com/stretchr/testify/assert" ) @@ -32,7 +33,7 @@ func TestFungibleUTXOs(t *testing.T) { Y: y, } salt, _ := new(big.Int).SetString("13de02d64a5736a56b2d35d2a83dd60397ba70aae6f8347629f0960d4fee5d58", 16) - utxo1 := NewFungible(big.NewInt(10), alice, salt) + utxo1 := NewFungible(big.NewInt(10), alice, salt, &hash.PoseidonHasher{}) idx1, err := utxo1.GetHash() assert.NoError(t, err) @@ -42,7 +43,7 @@ func TestFungibleUTXOs(t *testing.T) { func TestFungibleUTXOsWithNullifiers(t *testing.T) { privateKey, _ := new(big.Int).SetString("df7ff8191db562f4ed9404e91f184502fe67f880cd1fe67c0f84d224a53ee55", 16) salt, _ := new(big.Int).SetString("13de02d64a5736a56b2d35d2a83dd60397ba70aae6f8347629f0960d4fee5d58", 16) - utxo1 := NewFungibleNullifier(big.NewInt(10), privateKey, salt) + utxo1 := NewFungibleNullifier(big.NewInt(10), privateKey, salt, &hash.PoseidonHasher{}) idx1, err := utxo1.GetHash() assert.NoError(t, err) @@ -57,7 +58,7 @@ func TestFungibleUTXOsFail(t *testing.T) { Y: y, } salt, _ := new(big.Int).SetString("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16) - utxo1 := NewFungible(big.NewInt(10), alice, salt) + utxo1 := NewFungible(big.NewInt(10), alice, salt, &hash.PoseidonHasher{}) _, err := utxo1.GetHash() assert.EqualError(t, err, "inputs values not inside Finite Field") @@ -66,7 +67,7 @@ func TestFungibleUTXOsFail(t *testing.T) { func TestFungibleUTXOsWithNullifiersFail(t *testing.T) { privateKey, _ := new(big.Int).SetString("df7ff8191db562f4ed9404e91f184502fe67f880cd1fe67c0f84d224a53ee55", 16) salt, _ := new(big.Int).SetString("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16) - utxo1 := NewFungibleNullifier(big.NewInt(10), privateKey, salt) + utxo1 := NewFungibleNullifier(big.NewInt(10), privateKey, salt, &hash.PoseidonHasher{}) _, err := utxo1.GetHash() assert.EqualError(t, err, "inputs values not inside Finite Field") diff --git a/go-sdk/internal/utxo/nonfungible.go b/go-sdk/internal/utxo/nonfungible.go index 2302e2db..61856c3b 100644 --- a/go-sdk/internal/utxo/nonfungible.go +++ b/go-sdk/internal/utxo/nonfungible.go @@ -23,7 +23,6 @@ import ( "github.com/hyperledger-labs/zeto/go-sdk/pkg/utxo/core" "github.com/iden3/go-iden3-crypto/babyjub" - "github.com/iden3/go-iden3-crypto/poseidon" ) type nonFungible struct { @@ -31,14 +30,16 @@ type nonFungible struct { TokenUri string Owner *babyjub.PublicKey Salt *big.Int + hasher core.Hasher } -func NewNonFungible(tokenId *big.Int, tokenUri string, owner *babyjub.PublicKey, salt *big.Int) core.UTXO { +func NewNonFungible(tokenId *big.Int, tokenUri string, owner *babyjub.PublicKey, salt *big.Int, hasher core.Hasher) core.UTXO { return &nonFungible{ TokenId: tokenId, TokenUri: tokenUri, Owner: owner, Salt: salt, + hasher: hasher, } } @@ -47,7 +48,7 @@ func (f *nonFungible) GetHash() (*big.Int, error) { if err != nil { return nil, err } - hash, err := poseidon.Hash([]*big.Int{f.TokenId, tokenUriHash, f.Salt, f.Owner.X, f.Owner.Y}) + hash, err := f.hasher.Hash([]*big.Int{f.TokenId, tokenUriHash, f.Salt, f.Owner.X, f.Owner.Y}) if err != nil { return nil, err } @@ -62,14 +63,16 @@ type nonFungibleNullifier struct { TokenUri string Owner *big.Int Salt *big.Int + hasher core.Hasher } -func NewNonFungibleNullifier(tokenId *big.Int, tokenUri string, owner *big.Int, salt *big.Int) core.UTXO { +func NewNonFungibleNullifier(tokenId *big.Int, tokenUri string, owner *big.Int, salt *big.Int, hasher core.Hasher) core.UTXO { return &nonFungibleNullifier{ TokenId: tokenId, TokenUri: tokenUri, Owner: owner, Salt: salt, + hasher: hasher, } } @@ -78,7 +81,7 @@ func (f *nonFungibleNullifier) GetHash() (*big.Int, error) { if err != nil { return nil, err } - hash, err := poseidon.Hash([]*big.Int{f.TokenId, tokenUriHash, f.Salt, f.Owner}) + hash, err := f.hasher.Hash([]*big.Int{f.TokenId, tokenUriHash, f.Salt, f.Owner}) if err != nil { return nil, err } diff --git a/go-sdk/internal/utxo/nonfungible_test.go b/go-sdk/internal/utxo/nonfungible_test.go index ac2135bc..e8815178 100644 --- a/go-sdk/internal/utxo/nonfungible_test.go +++ b/go-sdk/internal/utxo/nonfungible_test.go @@ -20,6 +20,7 @@ import ( "math/big" "testing" + "github.com/hyperledger-labs/zeto/go-sdk/internal/crypto/hash" "github.com/iden3/go-iden3-crypto/babyjub" "github.com/stretchr/testify/assert" ) @@ -42,7 +43,7 @@ func TestNonFungibleUTXOs(t *testing.T) { } salt, _ := new(big.Int).SetString("14366367216420666010683918465570547601749064763665615379119566396413295472937", 10) uri := "http://ipfs.io/file-hash-1" - utxo1 := NewNonFungible(big.NewInt(1001), uri, alice, salt) + utxo1 := NewNonFungible(big.NewInt(1001), uri, alice, salt, &hash.PoseidonHasher{}) idx1, err := utxo1.GetHash() assert.NoError(t, err) @@ -53,7 +54,7 @@ func TestNonFungibleUTXOsWithNullifiers(t *testing.T) { privateKey, _ := new(big.Int).SetString("df7ff8191db562f4ed9404e91f184502fe67f880cd1fe67c0f84d224a53ee55", 16) salt, _ := new(big.Int).SetString("14366367216420666010683918465570547601749064763665615379119566396413295472937", 10) uri := "http://ipfs.io/file-hash-1" - utxo1 := NewNonFungibleNullifier(big.NewInt(1001), uri, privateKey, salt) + utxo1 := NewNonFungibleNullifier(big.NewInt(1001), uri, privateKey, salt, &hash.PoseidonHasher{}) idx1, err := utxo1.GetHash() assert.NoError(t, err) @@ -69,7 +70,7 @@ func TestNonFungibleUTXOsFail(t *testing.T) { } salt, _ := new(big.Int).SetString("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16) uri := "http://ipfs.io/file-hash-1" - utxo1 := NewNonFungible(big.NewInt(1001), uri, alice, salt) + utxo1 := NewNonFungible(big.NewInt(1001), uri, alice, salt, &hash.PoseidonHasher{}) _, err := utxo1.GetHash() assert.EqualError(t, err, "inputs values not inside Finite Field") } @@ -78,7 +79,7 @@ func TestNonFungibleUTXOsWithNullifiersFail(t *testing.T) { privateKey, _ := new(big.Int).SetString("df7ff8191db562f4ed9404e91f184502fe67f880cd1fe67c0f84d224a53ee55", 16) salt, _ := new(big.Int).SetString("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16) uri := "http://ipfs.io/file-hash-1" - utxo1 := NewNonFungibleNullifier(big.NewInt(1001), uri, privateKey, salt) + utxo1 := NewNonFungibleNullifier(big.NewInt(1001), uri, privateKey, salt, &hash.PoseidonHasher{}) _, err := utxo1.GetHash() assert.EqualError(t, err, "inputs values not inside Finite Field") } diff --git a/go-sdk/pkg/crypto/crypto.go b/go-sdk/pkg/crypto/crypto.go index f9c7a384..8d3446be 100644 --- a/go-sdk/pkg/crypto/crypto.go +++ b/go-sdk/pkg/crypto/crypto.go @@ -20,6 +20,8 @@ import ( "math/big" "github.com/hyperledger-labs/zeto/go-sdk/internal/crypto" + "github.com/hyperledger-labs/zeto/go-sdk/internal/crypto/hash" + "github.com/hyperledger-labs/zeto/go-sdk/pkg/utxo/core" "github.com/iden3/go-iden3-crypto/babyjub" ) @@ -60,3 +62,11 @@ func RecoverMlkemCiphertextBytes(ciphertext []string) ([]byte, error) { func PublicKeyFromSeed(seed []byte) (*babyjub.Point, error) { return crypto.PublicKeyFromSeed(seed) } + +func NewPoseidonHasher() core.Hasher { + return &hash.PoseidonHasher{} +} + +func NewKeccak256Hasher() core.Hasher { + return &hash.Keccak256Hasher{} +} diff --git a/go-sdk/pkg/sparse-merkle-tree/core/node.go b/go-sdk/pkg/sparse-merkle-tree/core/node.go index 31c6a378..3339792a 100644 --- a/go-sdk/pkg/sparse-merkle-tree/core/node.go +++ b/go-sdk/pkg/sparse-merkle-tree/core/node.go @@ -18,6 +18,8 @@ package core import ( "math/big" + + "github.com/hyperledger-labs/zeto/go-sdk/pkg/utxo/core" ) type NodeType int @@ -44,6 +46,8 @@ type NodeRef interface { IsZero() bool // Equal returns true if two reference hashes equal to each other Equal(NodeRef) bool + // GetHasher returns the hasher used to compute the node reference + GetHasher() core.Hasher } // NodeIndex defines the functions of leaf nodes in the SMT, which provide access to their node paths in addition to the NodeRef functions. @@ -59,6 +63,7 @@ type NodeIndex interface { // Node, which is used to produce a unique index for the node. type Indexable interface { CalculateIndex() (NodeIndex, error) + GetHasher() core.Hasher } // Node is the object of a node in the Sparse Merkle Tree, which has an diff --git a/go-sdk/pkg/sparse-merkle-tree/core/storage.go b/go-sdk/pkg/sparse-merkle-tree/core/storage.go index 7e3189bc..2c352587 100644 --- a/go-sdk/pkg/sparse-merkle-tree/core/storage.go +++ b/go-sdk/pkg/sparse-merkle-tree/core/storage.go @@ -16,7 +16,10 @@ package core -import "gorm.io/gorm" +import ( + "github.com/hyperledger-labs/zeto/go-sdk/pkg/utxo/core" + "gorm.io/gorm" +) type Storage interface { // GetRootNodeRef returns the root node index. @@ -35,6 +38,8 @@ type Storage interface { BeginTx() (Transaction, error) // Close closes the storage resource Close() + // GetHasher returns the hasher used by the storage + GetHasher() core.Hasher } type Transaction interface { diff --git a/go-sdk/pkg/sparse-merkle-tree/node/node.go b/go-sdk/pkg/sparse-merkle-tree/node/node.go index 3b8da0ff..47b03146 100644 --- a/go-sdk/pkg/sparse-merkle-tree/node/node.go +++ b/go-sdk/pkg/sparse-merkle-tree/node/node.go @@ -22,6 +22,7 @@ import ( "github.com/hyperledger-labs/zeto/go-sdk/internal/sparse-merkle-tree/node" "github.com/hyperledger-labs/zeto/go-sdk/internal/sparse-merkle-tree/utils" "github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/core" + apicore "github.com/hyperledger-labs/zeto/go-sdk/pkg/utxo/core" "github.com/iden3/go-iden3-crypto/babyjub" ) @@ -33,38 +34,38 @@ func NewEmptyNode() core.Node { // which is used to calculate the hash of the node index. // the value parameter is optional. if "nil", the index hash is used in the // place of the value when calculating the node reference hash (aka "node key"). -func NewLeafNode(i core.Indexable, v ...*big.Int) (core.Node, error) { - return node.NewLeafNode(i, v...) +func NewLeafNode(i core.Indexable, v *big.Int) (core.Node, error) { + return node.NewLeafNode(i, v) } -func NewBranchNode(leftChild, rightChild core.NodeRef) (core.Node, error) { - return node.NewBranchNode(leftChild, rightChild) +func NewBranchNode(leftChild, rightChild core.NodeRef, hasher apicore.Hasher) (core.Node, error) { + return node.NewBranchNode(leftChild, rightChild, hasher) } -func NewNodeIndexFromBigInt(i *big.Int) (core.NodeIndex, error) { - return node.NewNodeIndexFromBigInt(i) +func NewNodeIndexFromBigInt(i *big.Int, hasher apicore.Hasher) (core.NodeIndex, error) { + return node.NewNodeIndexFromBigInt(i, hasher) } // NewNodeIndexFromHex creates a new NodeIndex from a hex string that // represents the index in big-endian format. -func NewNodeIndexFromHex(h string) (core.NodeIndex, error) { - return node.NewNodeIndexFromHex(h) +func NewNodeIndexFromHex(h string, hasher apicore.Hasher) (core.NodeIndex, error) { + return node.NewNodeIndexFromHex(h, hasher) } -func NewFungible(amount *big.Int, owner *babyjub.PublicKey, salt *big.Int) core.Indexable { - return node.NewFungible(amount, owner, salt) +func NewFungible(amount *big.Int, owner *babyjub.PublicKey, salt *big.Int, hasher apicore.Hasher) core.Indexable { + return node.NewFungible(amount, owner, salt, hasher) } -func NewNonFungible(tokenId *big.Int, tokenUri string, owner *babyjub.PublicKey, salt *big.Int) core.Indexable { - return node.NewNonFungible(tokenId, tokenUri, owner, salt) +func NewNonFungible(tokenId *big.Int, tokenUri string, owner *babyjub.PublicKey, salt *big.Int, hasher apicore.Hasher) core.Indexable { + return node.NewNonFungible(tokenId, tokenUri, owner, salt, hasher) } -func NewFungibleNullifier(amount *big.Int, owner *big.Int, salt *big.Int) core.Indexable { - return node.NewFungibleNullifier(amount, owner, salt) +func NewFungibleNullifier(amount *big.Int, owner *big.Int, salt *big.Int, hasher apicore.Hasher) core.Indexable { + return node.NewFungibleNullifier(amount, owner, salt, hasher) } -func NewNonFungibleNullifier(tokenId *big.Int, tokenUri string, owner *big.Int, salt *big.Int) core.Indexable { - return node.NewNonFungibleNullifier(tokenId, tokenUri, owner, salt) +func NewNonFungibleNullifier(tokenId *big.Int, tokenUri string, owner *big.Int, salt *big.Int, hasher apicore.Hasher) core.Indexable { + return node.NewNonFungibleNullifier(tokenId, tokenUri, owner, salt, hasher) } func NewIndexOnly(index core.NodeIndex) core.Indexable { diff --git a/go-sdk/pkg/sparse-merkle-tree/storage/storage.go b/go-sdk/pkg/sparse-merkle-tree/storage/storage.go index 4147da26..590b428d 100644 --- a/go-sdk/pkg/sparse-merkle-tree/storage/storage.go +++ b/go-sdk/pkg/sparse-merkle-tree/storage/storage.go @@ -19,8 +19,9 @@ package storage import ( "github.com/hyperledger-labs/zeto/go-sdk/internal/sparse-merkle-tree/storage" "github.com/hyperledger-labs/zeto/go-sdk/pkg/sparse-merkle-tree/core" + apicore "github.com/hyperledger-labs/zeto/go-sdk/pkg/utxo/core" ) -func NewSqlStorage(provider core.SqlDBProvider, smtName string) (core.Storage, error) { - return storage.NewSqlStorage(provider, smtName), nil +func NewSqlStorage(provider core.SqlDBProvider, smtName string, hasher apicore.Hasher) (core.Storage, error) { + return storage.NewSqlStorage(provider, smtName, hasher), nil } diff --git a/go-sdk/pkg/utxo/core/api.go b/go-sdk/pkg/utxo/core/api.go index 120c4170..177371c2 100644 --- a/go-sdk/pkg/utxo/core/api.go +++ b/go-sdk/pkg/utxo/core/api.go @@ -21,3 +21,8 @@ import "math/big" type UTXO interface { GetHash() (*big.Int, error) } + +type Hasher interface { + Hash([]*big.Int) (*big.Int, error) + CheckInRange(a *big.Int) bool +} diff --git a/go-sdk/pkg/utxo/utxo.go b/go-sdk/pkg/utxo/utxo.go index 548e2a78..6d164e46 100644 --- a/go-sdk/pkg/utxo/utxo.go +++ b/go-sdk/pkg/utxo/utxo.go @@ -24,20 +24,20 @@ import ( "github.com/iden3/go-iden3-crypto/babyjub" ) -func NewFungible(amount *big.Int, owner *babyjub.PublicKey, salt *big.Int) core.UTXO { - return utxo.NewFungible(amount, owner, salt) +func NewFungible(amount *big.Int, owner *babyjub.PublicKey, salt *big.Int, hasher core.Hasher) core.UTXO { + return utxo.NewFungible(amount, owner, salt, hasher) } -func NewNonFungible(tokenId *big.Int, tokenUri string, owner *babyjub.PublicKey, salt *big.Int) core.UTXO { - return utxo.NewNonFungible(tokenId, tokenUri, owner, salt) +func NewNonFungible(tokenId *big.Int, tokenUri string, owner *babyjub.PublicKey, salt *big.Int, hasher core.Hasher) core.UTXO { + return utxo.NewNonFungible(tokenId, tokenUri, owner, salt, hasher) } -func NewFungibleNullifier(amount *big.Int, owner *big.Int, salt *big.Int) core.UTXO { - return utxo.NewFungibleNullifier(amount, owner, salt) +func NewFungibleNullifier(amount *big.Int, owner *big.Int, salt *big.Int, hasher core.Hasher) core.UTXO { + return utxo.NewFungibleNullifier(amount, owner, salt, hasher) } -func NewNonFungibleNullifier(tokenId *big.Int, tokenUri string, owner *big.Int, salt *big.Int) core.UTXO { - return utxo.NewNonFungibleNullifier(tokenId, tokenUri, owner, salt) +func NewNonFungibleNullifier(tokenId *big.Int, tokenUri string, owner *big.Int, salt *big.Int, hasher core.Hasher) core.UTXO { + return utxo.NewNonFungibleNullifier(tokenId, tokenUri, owner, salt, hasher) } func HashTokenUri(tokenUri string) (*big.Int, error) {