mirror of
https://github.com/vocdoni/arbo.git
synced 2026-01-07 21:14:02 -05:00
use the smt verifier for testing compatibility with gnark
Signed-off-by: p4u <pau@dabax.net>
This commit is contained in:
89
gnark.go
89
gnark.go
@@ -1,6 +1,10 @@
|
||||
package arbo
|
||||
|
||||
import "math/big"
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"go.vocdoni.io/dvote/tree/arbo"
|
||||
)
|
||||
|
||||
// GnarkVerifierProof is a struct that contains all the information needed to
|
||||
// verify a proof in a gnark circuit. The attributes are all big.Int, so they
|
||||
@@ -18,53 +22,70 @@ type GnarkVerifierProof struct {
|
||||
Fnc *big.Int
|
||||
}
|
||||
|
||||
// GenerateGnarkVerifierProof generates a GnarkVerifierProof for a given key
|
||||
// in the Tree. Every attribute is a big.Int, so it can be used in the gnark
|
||||
// circuit as frontend.Variable's. The endianess of root, siblings and value
|
||||
// has been changed to Little-Endian to match the gnark arbo verifier.
|
||||
func (t *Tree) GenerateGnarkVerifierProof(k []byte) (*GnarkVerifierProof, error) {
|
||||
// generate the arbo proof
|
||||
oldKey, value, siblings, existence, err := t.GenProof(k)
|
||||
// GenerateGnarkVerifierProofLE builds a proof whose Root, Siblings and Value
|
||||
// are **little-endian**, matching the arbo Poseidon-2 circuit.
|
||||
func (t *Tree) GenerateGnarkVerifierProofLE(keyBE []byte) (*GnarkVerifierProof, error) {
|
||||
return t.genVerifierProof(keyBE, arbo.BytesLEToBigInt)
|
||||
}
|
||||
|
||||
// GenerateGnarkVerifierProofBE builds an equivalent proof but keeps the
|
||||
// canonical **big-endian** encoding (handy for off-chain checks & logs).
|
||||
func (t *Tree) GenerateGnarkVerifierProofBE(keyBE []byte) (*GnarkVerifierProof, error) {
|
||||
return t.genVerifierProof(keyBE, BytesToBigInt)
|
||||
}
|
||||
|
||||
// genVerifierProof contains the full algorithm; the only difference between
|
||||
// LE / BE variants is the `conv` function used to turn each byte slice into a
|
||||
// *big.Int*. No other logic diverges.
|
||||
func (t *Tree) genVerifierProof(
|
||||
keyBE []byte,
|
||||
conv func([]byte) *big.Int, // endian-aware byte-slice → big.Int
|
||||
) (*GnarkVerifierProof, error) {
|
||||
|
||||
// 1. build the sparse-Merkle proof through arbo
|
||||
oldKey, value, sibPacked, exists, err := t.GenProof(keyBE)
|
||||
if err != nil && err != ErrKeyNotFound {
|
||||
return nil, err
|
||||
}
|
||||
// get the root of the tree
|
||||
root, err := t.Root()
|
||||
|
||||
// 2. current tree root
|
||||
rootBE, err := t.Root()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// unpack the siblings
|
||||
unpackedSiblings, err := UnpackSiblings(t.hashFunction, siblings)
|
||||
|
||||
// 3. unpack and convert each sibling
|
||||
unpacked, err := UnpackSiblings(t.hashFunction, sibPacked)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// convert the siblings to big.Int swapping the endianess
|
||||
bigSiblings := make([]*big.Int, len(unpackedSiblings))
|
||||
for i := range bigSiblings {
|
||||
bigSiblings[i] = BytesToBigInt(unpackedSiblings[i])
|
||||
siblings := make([]*big.Int, len(unpacked))
|
||||
for i := range unpacked {
|
||||
siblings[i] = conv(unpacked[i])
|
||||
}
|
||||
// initialize the GnarkVerifierProof
|
||||
gp := GnarkVerifierProof{
|
||||
Root: BytesToBigInt(root),
|
||||
Key: BytesToBigInt(k),
|
||||
Value: BytesToBigInt(value),
|
||||
Siblings: bigSiblings,
|
||||
|
||||
// 4. assemble the witness
|
||||
proof := &GnarkVerifierProof{
|
||||
Root: conv(rootBE),
|
||||
Key: conv(keyBE),
|
||||
Value: conv(value),
|
||||
Siblings: siblings,
|
||||
|
||||
// default for inclusion
|
||||
OldKey: big.NewInt(0),
|
||||
OldValue: big.NewInt(0),
|
||||
IsOld0: big.NewInt(0),
|
||||
Fnc: big.NewInt(0), // inclusion
|
||||
}
|
||||
// if the arbo proof is for a non-existing key, set the old key and value
|
||||
// to the key and value of the proof
|
||||
if !existence {
|
||||
gp.OldKey = BytesToBigInt(oldKey)
|
||||
gp.OldValue = BytesToBigInt(value)
|
||||
gp.Fnc = big.NewInt(1) // exclusion
|
||||
Fnc: big.NewInt(0),
|
||||
}
|
||||
|
||||
// set the IsOld0 attribute to 1 if there is no old key
|
||||
if len(oldKey) == 0 {
|
||||
gp.IsOld0 = big.NewInt(1)
|
||||
// 5. adjust flags for exclusion proofs
|
||||
if !exists {
|
||||
proof.OldKey = conv(oldKey)
|
||||
proof.OldValue = conv(value)
|
||||
proof.Fnc = big.NewInt(1) // exclusion
|
||||
}
|
||||
return &gp, nil
|
||||
if len(oldKey) == 0 {
|
||||
proof.IsOld0 = big.NewInt(1)
|
||||
}
|
||||
return proof, nil
|
||||
}
|
||||
|
||||
4
go.mod
4
go.mod
@@ -6,7 +6,7 @@ require (
|
||||
github.com/consensys/gnark-crypto v0.17.1-0.20250415133755-1873045cbd7d
|
||||
github.com/frankban/quicktest v1.14.6
|
||||
github.com/iden3/go-iden3-crypto v0.0.17
|
||||
github.com/vocdoni/vocdoni-z-sandbox v0.0.0-20241212172703-15f6d0594b8e
|
||||
github.com/vocdoni/vocdoni-z-sandbox v0.0.0-20241216104229-fa0b063e636c
|
||||
go.vocdoni.io/dvote v1.10.2-0.20241024102542-c1ce6d744bc5
|
||||
golang.org/x/crypto v0.35.0
|
||||
)
|
||||
@@ -28,6 +28,7 @@ require (
|
||||
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
github.com/klauspost/compress v1.17.9 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
|
||||
github.com/kr/pretty v0.3.1 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/mmcloughlin/addchain v0.4.0 // indirect
|
||||
@@ -42,5 +43,6 @@ require (
|
||||
golang.org/x/sys v0.30.0 // indirect
|
||||
golang.org/x/text v0.22.0 // indirect
|
||||
google.golang.org/protobuf v1.34.2 // indirect
|
||||
lukechampine.com/blake3 v1.3.0 // indirect
|
||||
rsc.io/tmplfunc v0.0.3 // indirect
|
||||
)
|
||||
|
||||
9
go.sum
9
go.sum
@@ -53,6 +53,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
|
||||
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
||||
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
|
||||
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
@@ -100,8 +102,8 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a h1:1ur3QoCqvE5fl+nylMaIr9PVV1w343YRDtsy+Rwu7XI=
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48=
|
||||
github.com/vocdoni/vocdoni-z-sandbox v0.0.0-20241212172703-15f6d0594b8e h1:sogZy0UOcDvg4mAeU0vXFDNgymLd4WqwfQImlEdevqw=
|
||||
github.com/vocdoni/vocdoni-z-sandbox v0.0.0-20241212172703-15f6d0594b8e/go.mod h1:8GkK2SCGHZ8d8SE4AsWWnVnUQxI8vx75KJDCv2yrZlY=
|
||||
github.com/vocdoni/vocdoni-z-sandbox v0.0.0-20241216104229-fa0b063e636c h1:0KJ3ufAYWGpdXgdlnLjFblW98MK+KfdYUiXzKPtk9PA=
|
||||
github.com/vocdoni/vocdoni-z-sandbox v0.0.0-20241216104229-fa0b063e636c/go.mod h1:mFXFbumAbxySlviwrGiclFPRiSDIs4WzXnQQqPyNX9k=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
||||
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
|
||||
@@ -139,6 +141,7 @@ golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
||||
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
@@ -157,5 +160,7 @@ google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6h
|
||||
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
lukechampine.com/blake3 v1.3.0 h1:sJ3XhFINmHSrYCgl958hscfIa3bw8x4DqMP3u1YvoYE=
|
||||
lukechampine.com/blake3 v1.3.0/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k=
|
||||
rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU=
|
||||
rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA=
|
||||
|
||||
@@ -177,6 +177,7 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/crackcomm/go-gitignore v0.0.0-20231225121904-e25f5bc08668/go.mod h1:p1d6YEZWvFzEh4KLyvBcVSnrfNDDvK2zfK/4x2v/4pE=
|
||||
github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c h1:uQYC5Z1mdLRPrZhHjHxufI8+2UG/i25QG92j0Er9p6I=
|
||||
github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs=
|
||||
github.com/crate-crypto/go-kzg-4844 v1.0.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc=
|
||||
github.com/cskr/pubsub v1.0.2/go.mod h1:/8MzYXk/NJAz782G8RPkFzXTZVu63VotefPnR9TIRis=
|
||||
@@ -221,6 +222,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.m
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/esimonov/ifshort v1.0.4/go.mod h1:Pe8zjlRrJ80+q2CxHLfEOfTwxCZ4O+MuhcHcfgNWTk0=
|
||||
github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
|
||||
github.com/ethereum/go-ethereum v1.14.12 h1:8hl57x77HSUo+cXExrURjU/w1VhL+ShCTJrTwcCQSe4=
|
||||
github.com/ethereum/go-ethereum v1.14.12/go.mod h1:RAC2gVMWJ6FkxSPESfbshrcKpIokgQKsVKmAuqdekDY=
|
||||
github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0/go.mod h1:D9AJLVXSyZQXJQVk8oh1EwjISE+sJTn2duYIZC0dy3w=
|
||||
github.com/ethereum/go-verkle v0.1.1-0.20240829091221-dffa7562dbe9/go.mod h1:M3b90YRnzqKyyzBEWJGqj8Qff4IDeXnzFw0P9bFw3uk=
|
||||
github.com/ettle/strcase v0.1.1/go.mod h1:hzDLsPC7/lwKyBOywSHEP89nt2pDgdy+No1NBA9o9VY=
|
||||
@@ -251,6 +254,8 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME
|
||||
github.com/ghostiam/protogetter v0.2.3/go.mod h1:KmNLOsy1v04hKbvZs8EfGI1fk39AgTdRDxWNYPfXVc4=
|
||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||
github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk=
|
||||
github.com/glendc/go-external-ip v0.1.0 h1:iX3xQ2Q26atAmLTbd++nUce2P5ht5P4uD4V7caSY/xg=
|
||||
github.com/glendc/go-external-ip v0.1.0/go.mod h1:CNx312s2FLAJoWNdJWZ2Fpf5O4oLsMFwuYviHjS4uJE=
|
||||
github.com/go-chi/chi v4.1.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
|
||||
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
|
||||
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
|
||||
@@ -431,6 +436,8 @@ github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/J
|
||||
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
|
||||
github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4/go.mod h1:5GuXa7vkL8u9FkFuWdVvfR5ix8hRB7DbOAaYULamFpc=
|
||||
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
|
||||
github.com/holiman/uint256 v1.3.1 h1:JfTzmih28bittyHM8z360dCjIA9dbPIBlcTI6lmctQs=
|
||||
github.com/holiman/uint256 v1.3.1/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
|
||||
github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
|
||||
@@ -826,6 +833,8 @@ github.com/vektra/mockery/v2 v2.38.0/go.mod h1:diB13hxXG6QrTR0ol2Rk8s2dRMftzvExS
|
||||
github.com/vertica/vertica-sql-go v1.3.3/go.mod h1:jnn2GFuv+O2Jcjktb7zyc4Utlbu9YVqpHH/lx63+1M4=
|
||||
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
|
||||
github.com/vocdoni/arbo v0.0.0-20241216103934-e64315269b49/go.mod h1:wXxPP+5vkT5t54lrKz6bCXKIyv8aRplKq8uCFb2wgy4=
|
||||
github.com/vocdoni/arbo v0.0.0-20250428090545-2b68f3f093d4/go.mod h1:SHdatjsIiJQjEHeWcRKhdS/39/axKCpZDLaROIg+wbI=
|
||||
github.com/vocdoni/circom2gnark v1.0.1-0.20241118090531-f24bf0de0e2f/go.mod h1:A1WU0hL7rO9oZlvp82you2uCc4T3/ySi1UNW6N6hBJs=
|
||||
github.com/vocdoni/gnark-crypto-primitives v0.0.2-0.20241202120611-440afa35dda9 h1:Rqn0WatSmye3SKLOXPnyYRNBvRkunzB/zmWTVHKG8KA=
|
||||
github.com/vocdoni/gnark-crypto-primitives v0.0.2-0.20241202120611-440afa35dda9/go.mod h1:SUX2CyNDyq8uLPkqlizmYa8kDBpSsgCrIgcL+JdgfEI=
|
||||
|
||||
@@ -13,12 +13,10 @@ import (
|
||||
"github.com/vocdoni/arbo"
|
||||
"github.com/vocdoni/arbo/memdb"
|
||||
"github.com/vocdoni/gnark-crypto-primitives/hash/bn254/poseidon"
|
||||
garbo "github.com/vocdoni/gnark-crypto-primitives/tree/arbo"
|
||||
gsmt "github.com/vocdoni/gnark-crypto-primitives/tree/smt"
|
||||
"github.com/vocdoni/gnark-crypto-primitives/utils"
|
||||
)
|
||||
|
||||
const nLevels = 160
|
||||
const nLevels = 64
|
||||
|
||||
type testCircuitArbo struct {
|
||||
Root frontend.Variable
|
||||
@@ -28,7 +26,8 @@ type testCircuitArbo struct {
|
||||
}
|
||||
|
||||
func (circuit *testCircuitArbo) Define(api frontend.API) error {
|
||||
return garbo.CheckInclusionProof(api, utils.Poseidon2Hasher, circuit.Key, circuit.Value, circuit.Root, circuit.Siblings[:])
|
||||
gsmt.InclusionVerifier(api, poseidon.Hash, circuit.Root, circuit.Siblings[:], circuit.Key, circuit.Value)
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestGnarkArboVerifier(t *testing.T) {
|
||||
@@ -36,7 +35,7 @@ func TestGnarkArboVerifier(t *testing.T) {
|
||||
tree, err := arbo.NewTree(arbo.Config{
|
||||
Database: memdb.New(),
|
||||
MaxLevels: nLevels,
|
||||
HashFunction: arbo.HashFunctionPoseidon2,
|
||||
HashFunction: arbo.HashFunctionPoseidon,
|
||||
})
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
@@ -72,7 +71,7 @@ func TestGnarkArboVerifier(t *testing.T) {
|
||||
Root: proof.Root,
|
||||
Key: proof.Key,
|
||||
Value: proof.Value,
|
||||
Siblings: [160]frontend.Variable(paddedSiblings),
|
||||
Siblings: [nLevels]frontend.Variable(paddedSiblings),
|
||||
}, test.WithCurves(ecc.BN254), test.WithBackends(backend.GROTH16))
|
||||
}
|
||||
|
||||
@@ -129,6 +128,6 @@ func TestGnarkSMTVerifier(t *testing.T) {
|
||||
Root: proof.Root,
|
||||
Key: proof.Key,
|
||||
Value: proof.Value,
|
||||
Siblings: [160]frontend.Variable(paddedSiblings),
|
||||
Siblings: [nLevels]frontend.Variable(paddedSiblings),
|
||||
}, test.WithCurves(ecc.BN254), test.WithBackends(backend.GROTH16))
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ require (
|
||||
github.com/consensys/gnark v0.12.1-0.20250417131611-fdeeb39f3a62
|
||||
github.com/consensys/gnark-crypto v0.17.1-0.20250415133755-1873045cbd7d
|
||||
github.com/frankban/quicktest v1.14.6
|
||||
github.com/vocdoni/arbo v0.0.0-20241216103934-e64315269b49
|
||||
github.com/vocdoni/gnark-crypto-primitives v0.0.2-0.20250427214622-8b2332f9feed
|
||||
github.com/vocdoni/arbo v0.0.0-20250429134936-21b6eda5d59a
|
||||
github.com/vocdoni/gnark-crypto-primitives v0.0.2-0.20250429135323-8566075e1249
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
@@ -33,18 +33,12 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/ethereum/go-ethereum v1.14.12 h1:8hl57x77HSUo+cXExrURjU/w1VhL+ShCTJrTwcCQSe4=
|
||||
github.com/ethereum/go-ethereum v1.14.12/go.mod h1:RAC2gVMWJ6FkxSPESfbshrcKpIokgQKsVKmAuqdekDY=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
|
||||
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
|
||||
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/glendc/go-external-ip v0.1.0 h1:iX3xQ2Q26atAmLTbd++nUce2P5ht5P4uD4V7caSY/xg=
|
||||
github.com/glendc/go-external-ip v0.1.0/go.mod h1:CNx312s2FLAJoWNdJWZ2Fpf5O4oLsMFwuYviHjS4uJE=
|
||||
github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU=
|
||||
github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0=
|
||||
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
|
||||
@@ -60,8 +54,6 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
|
||||
github.com/google/pprof v0.0.0-20241101162523-b92577c0c142 h1:sAGdeJj0bnMgUNVeUpp6AYlVdCt3/GdI3pGRqsNSQLs=
|
||||
github.com/google/pprof v0.0.0-20241101162523-b92577c0c142/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
|
||||
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
|
||||
github.com/holiman/uint256 v1.3.1 h1:JfTzmih28bittyHM8z360dCjIA9dbPIBlcTI6lmctQs=
|
||||
github.com/holiman/uint256 v1.3.1/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
|
||||
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/ingonyama-zk/icicle-gnark/v3 v3.2.2 h1:B+aWVgAx+GlFLhtYjIaF0uGjU3rzpl99Wf9wZWt+Mq8=
|
||||
@@ -120,14 +112,10 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a h1:1ur3QoCqvE5fl+nylMaIr9PVV1w343YRDtsy+Rwu7XI=
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48=
|
||||
github.com/vocdoni/arbo v0.0.0-20241216103934-e64315269b49 h1:GMyepEuxLflqhdDHts/eUMtVkbrCI5mJc8RVdlwZBoA=
|
||||
github.com/vocdoni/arbo v0.0.0-20241216103934-e64315269b49/go.mod h1:wXxPP+5vkT5t54lrKz6bCXKIyv8aRplKq8uCFb2wgy4=
|
||||
github.com/vocdoni/gnark-crypto-primitives v0.0.2-0.20250328120724-f9a3af9a3ace h1:ElTiK0ztqX/MAeFJXjjWNUyXrKXyHrt295rP6O2jf1w=
|
||||
github.com/vocdoni/gnark-crypto-primitives v0.0.2-0.20250328120724-f9a3af9a3ace/go.mod h1:L3OY0etasbmuSwOnAdNq7JnPuR7jY4A/wtFIlWvPhiU=
|
||||
github.com/vocdoni/gnark-crypto-primitives v0.0.2-0.20250427192533-d19393f004c4 h1:Q1z7/dcrRjA648bAzfcJUXiJbn3UDKumN6Md6CYIqkw=
|
||||
github.com/vocdoni/gnark-crypto-primitives v0.0.2-0.20250427192533-d19393f004c4/go.mod h1:eqkdjh1thkV+1uk/hA58LJOpLykz+kC9+/scqys4aYQ=
|
||||
github.com/vocdoni/gnark-crypto-primitives v0.0.2-0.20250427214622-8b2332f9feed h1:wCYTVsXGPxLvI/C7DJaHp5Nb/oXiV0RHWr3klm04WGg=
|
||||
github.com/vocdoni/gnark-crypto-primitives v0.0.2-0.20250427214622-8b2332f9feed/go.mod h1:eqkdjh1thkV+1uk/hA58LJOpLykz+kC9+/scqys4aYQ=
|
||||
github.com/vocdoni/arbo v0.0.0-20250429134936-21b6eda5d59a h1:PRldQ1sHilQXallGWyCDd1QcuqLUM2HHeirBGWzlrZI=
|
||||
github.com/vocdoni/arbo v0.0.0-20250429134936-21b6eda5d59a/go.mod h1:SHdatjsIiJQjEHeWcRKhdS/39/axKCpZDLaROIg+wbI=
|
||||
github.com/vocdoni/gnark-crypto-primitives v0.0.2-0.20250429135323-8566075e1249 h1:656+aAMVPiWEMco1E4CvsoWUejG+9LndqrLOyO+OqRw=
|
||||
github.com/vocdoni/gnark-crypto-primitives v0.0.2-0.20250429135323-8566075e1249/go.mod h1:P0d5S3ROhQb1wGMTycZ7VHzHun5Ge67Cf3JrIJXCj9A=
|
||||
github.com/vocdoni/vocdoni-z-sandbox v0.0.0-20241216104229-fa0b063e636c h1:0KJ3ufAYWGpdXgdlnLjFblW98MK+KfdYUiXzKPtk9PA=
|
||||
github.com/vocdoni/vocdoni-z-sandbox v0.0.0-20241216104229-fa0b063e636c/go.mod h1:mFXFbumAbxySlviwrGiclFPRiSDIs4WzXnQQqPyNX9k=
|
||||
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
|
||||
|
||||
@@ -168,7 +168,7 @@ func (t *Tree) GenerateGnarkVerifierProofBigInt(k *big.Int) (*GnarkVerifierProof
|
||||
return nil, fmt.Errorf("key cannot be nil")
|
||||
}
|
||||
bk := bigIntToLeafKey(k, t.MaxKeyLen())
|
||||
return t.GenerateGnarkVerifierProof(bk)
|
||||
return t.GenerateGnarkVerifierProofLE(bk)
|
||||
}
|
||||
|
||||
// leafToBigInts converts the bytes of the key and the value of a leaf node
|
||||
|
||||
Reference in New Issue
Block a user