mirror of
https://github.com/arnaucube/go-merkletree-iden3.git
synced 2026-02-06 19:16:43 +01:00
Update Poseidon version, add mt.Snapshot
This commit is contained in:
2
go.mod
2
go.mod
@@ -4,7 +4,7 @@ go 1.14
|
||||
|
||||
require (
|
||||
github.com/iden3/go-iden3-core v0.0.8
|
||||
github.com/iden3/go-iden3-crypto v0.0.5
|
||||
github.com/iden3/go-iden3-crypto v0.0.6-0.20200723082457-29a66457f0bf
|
||||
github.com/sirupsen/logrus v1.5.0
|
||||
github.com/stretchr/testify v1.5.1
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d
|
||||
|
||||
2
go.sum
2
go.sum
@@ -114,6 +114,8 @@ github.com/iden3/go-iden3-core v0.0.8 h1:PLw7iCiX7Pw1dqBkR+JaLQWqB5RKd+vgu25UBdv
|
||||
github.com/iden3/go-iden3-core v0.0.8/go.mod h1:URNjIhMql6sEbWubIGrjJdw5wHCE1Pk1XghxjBOtA3s=
|
||||
github.com/iden3/go-iden3-crypto v0.0.5 h1:inCSm5a+ry+nbpVTL/9+m6UcIwSv6nhUm0tnIxEbcps=
|
||||
github.com/iden3/go-iden3-crypto v0.0.5/go.mod h1:XKw1oDwYn2CIxKOtr7m/mL5jMn4mLOxAxtZBRxQBev8=
|
||||
github.com/iden3/go-iden3-crypto v0.0.6-0.20200723082457-29a66457f0bf h1:/7L5dEqctuzJY2g8OEQct+1Y+n2sMKyd4JoYhw2jy1s=
|
||||
github.com/iden3/go-iden3-crypto v0.0.6-0.20200723082457-29a66457f0bf/go.mod h1:XKw1oDwYn2CIxKOtr7m/mL5jMn4mLOxAxtZBRxQBev8=
|
||||
github.com/iden3/go-wasm3 v0.0.1/go.mod h1:j+TcAB94Dfrjlu5kJt83h2OqAU+oyNUTwNZnQyII1sI=
|
||||
github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY=
|
||||
github.com/influxdata/influxdb v1.7.8/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY=
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/iden3/go-iden3-core/common"
|
||||
"github.com/iden3/go-merkletree/db"
|
||||
cryptoUtils "github.com/iden3/go-iden3-crypto/utils"
|
||||
"github.com/iden3/go-merkletree/db"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -141,6 +141,16 @@ func (mt *MerkleTree) Root() *Hash {
|
||||
return mt.rootKey
|
||||
}
|
||||
|
||||
func (mt *MerkleTree) Snapshot(rootKey *Hash) (*MerkleTree, error) {
|
||||
mt.RLock()
|
||||
defer mt.RUnlock()
|
||||
_, err := mt.GetNode(rootKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &MerkleTree{db: mt.db, maxLevels: mt.maxLevels, rootKey: rootKey, writable: false}, nil
|
||||
}
|
||||
|
||||
// Add adds a Key & Value into the MerkleTree. Where the `k` determines the path from the Root to the Leaf.
|
||||
func (mt *MerkleTree) Add(k, v *big.Int) error {
|
||||
// verify that the MerkleTree is writable
|
||||
|
||||
6
utils.go
6
utils.go
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
// HashElems performs a poseidon hash over the array of ElemBytes.
|
||||
// Uses poseidon.PoseidonHash to be compatible with the circom circuits
|
||||
// Uses poseidon.Hash to be compatible with the circom circuits
|
||||
// implementations.
|
||||
// The maxim slice input size is poseidon.T
|
||||
func HashElems(elems ...*big.Int) (*Hash, error) {
|
||||
@@ -21,7 +21,7 @@ func HashElems(elems ...*big.Int) (*Hash, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
poseidonHash, err := poseidon.PoseidonHash(bi)
|
||||
poseidonHash, err := poseidon.Hash(bi)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -41,7 +41,7 @@ func HashElemsKey(key *big.Int, elems ...*big.Int) (*Hash, error) {
|
||||
return nil, err
|
||||
}
|
||||
copy(bi[len(elems):], []*big.Int{key})
|
||||
poseidonHash, err := poseidon.PoseidonHash(bi)
|
||||
poseidonHash, err := poseidon.Hash(bi)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user