mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-12 06:53:46 +00:00
feat(zktrie): upgrade to 0.8.2 (#715)
* feat(zktrie): upgrade to v0.8.2 * chore: auto version bump [bot] * chore: auto version bump [bot] --------- Co-authored-by: omerfirmak <omerfirmak@users.noreply.github.com> Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> Co-authored-by: HAOYUatHZ <HAOYUatHZ@users.noreply.github.com>
This commit is contained in:
parent
90221d6fc7
commit
79c356002c
6 changed files with 24 additions and 24 deletions
2
go.mod
2
go.mod
|
|
@ -50,7 +50,7 @@ require (
|
||||||
github.com/prometheus/tsdb v0.7.1
|
github.com/prometheus/tsdb v0.7.1
|
||||||
github.com/rjeczalik/notify v0.9.1
|
github.com/rjeczalik/notify v0.9.1
|
||||||
github.com/rs/cors v1.7.0
|
github.com/rs/cors v1.7.0
|
||||||
github.com/scroll-tech/zktrie v0.6.0
|
github.com/scroll-tech/zktrie v0.8.2
|
||||||
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible
|
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible
|
||||||
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4
|
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4
|
||||||
github.com/stretchr/testify v1.8.2
|
github.com/stretchr/testify v1.8.2
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -386,8 +386,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
|
||||||
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
|
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
|
||||||
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
|
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
|
||||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/scroll-tech/zktrie v0.6.0 h1:xLrMAO31Yo2BiPg1jtYKzcjpEFnXy8acbB7iIsyshPs=
|
github.com/scroll-tech/zktrie v0.8.2 h1:UMuIfA+jdgWMLmTgTL64Emo+zzMOdcnH0+eYdDcshxQ=
|
||||||
github.com/scroll-tech/zktrie v0.6.0/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk=
|
github.com/scroll-tech/zktrie v0.8.2/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk=
|
||||||
github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=
|
github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=
|
||||||
github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=
|
github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=
|
||||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
const (
|
const (
|
||||||
VersionMajor = 5 // Major version component of the current release
|
VersionMajor = 5 // Major version component of the current release
|
||||||
VersionMinor = 3 // Minor version component of the current release
|
VersionMinor = 3 // Minor version component of the current release
|
||||||
VersionPatch = 1 // Patch version component of the current release
|
VersionPatch = 2 // Patch version component of the current release
|
||||||
VersionMeta = "mainnet" // Version metadata to append to the version string
|
VersionMeta = "mainnet" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,9 @@ func (t *ZkTrie) GetKey(kHashBytes []byte) []byte {
|
||||||
// Committing flushes nodes from memory. Subsequent Get calls will load nodes
|
// Committing flushes nodes from memory. Subsequent Get calls will load nodes
|
||||||
// from the database.
|
// from the database.
|
||||||
func (t *ZkTrie) Commit(LeafCallback) (common.Hash, int, error) {
|
func (t *ZkTrie) Commit(LeafCallback) (common.Hash, int, error) {
|
||||||
|
if err := t.ZkTrie.Commit(); err != nil {
|
||||||
|
return common.Hash{}, 0, err
|
||||||
|
}
|
||||||
// in current implmentation, every update of trie already writes into database
|
// in current implmentation, every update of trie already writes into database
|
||||||
// so Commmit does nothing
|
// so Commmit does nothing
|
||||||
return t.Hash(), 0, nil
|
return t.Hash(), 0, nil
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,11 @@ func TestSMTOneElementProof(t *testing.T) {
|
||||||
if proof.Len() != 2 {
|
if proof.Len() != 2 {
|
||||||
t.Errorf("prover %d: proof should have 1+1 element (including the magic kv)", i)
|
t.Errorf("prover %d: proof should have 1+1 element (including the magic kv)", i)
|
||||||
}
|
}
|
||||||
val, err := VerifyProof(common.BytesToHash(mt.Root().Bytes()), keyBytes, proof)
|
|
||||||
|
root, err := mt.Root()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
val, err := VerifyProof(common.BytesToHash(root.Bytes()), keyBytes, proof)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("prover %d: failed to verify proof: %v\nraw proof: %x", i, err, proof)
|
t.Fatalf("prover %d: failed to verify proof: %v\nraw proof: %x", i, err, proof)
|
||||||
}
|
}
|
||||||
|
|
@ -91,7 +95,9 @@ func TestSMTOneElementProof(t *testing.T) {
|
||||||
|
|
||||||
func TestSMTProof(t *testing.T) {
|
func TestSMTProof(t *testing.T) {
|
||||||
mt, vals := randomZktrie(t, 500)
|
mt, vals := randomZktrie(t, 500)
|
||||||
root := mt.Tree().Root()
|
root, err := mt.Tree().Root()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
for i, prover := range makeSMTProvers(mt) {
|
for i, prover := range makeSMTProvers(mt) {
|
||||||
for _, kv := range vals {
|
for _, kv := range vals {
|
||||||
proof := prover(kv.k)
|
proof := prover(kv.k)
|
||||||
|
|
@ -111,7 +117,9 @@ func TestSMTProof(t *testing.T) {
|
||||||
|
|
||||||
func TestSMTBadProof(t *testing.T) {
|
func TestSMTBadProof(t *testing.T) {
|
||||||
mt, vals := randomZktrie(t, 500)
|
mt, vals := randomZktrie(t, 500)
|
||||||
root := mt.Tree().Root()
|
root, err := mt.Tree().Root()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
for i, prover := range makeSMTProvers(mt) {
|
for i, prover := range makeSMTProvers(mt) {
|
||||||
for _, kv := range vals {
|
for _, kv := range vals {
|
||||||
proof := prover(kv.k)
|
proof := prover(kv.k)
|
||||||
|
|
@ -157,7 +165,11 @@ func TestSMTMissingKeyProof(t *testing.T) {
|
||||||
if proof.Len() != 2 {
|
if proof.Len() != 2 {
|
||||||
t.Errorf("test %d: proof should have 2 element (with magic kv)", i)
|
t.Errorf("test %d: proof should have 2 element (with magic kv)", i)
|
||||||
}
|
}
|
||||||
val, err := VerifyProof(common.BytesToHash(mt.Root().Bytes()), keyBytes, proof)
|
|
||||||
|
root, err := mt.Root()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
val, err := VerifyProof(common.BytesToHash(root.Bytes()), keyBytes, proof)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("test %d: failed to verify proof: %v\nraw proof: %x", i, err, proof)
|
t.Fatalf("test %d: failed to verify proof: %v\nraw proof: %x", i, err, proof)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,21 +10,6 @@ import (
|
||||||
"github.com/scroll-tech/go-ethereum/ethdb"
|
"github.com/scroll-tech/go-ethereum/ethdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Pick Node from its hash directly from database, notice it has different
|
|
||||||
// interface with the function of same name in `trie`
|
|
||||||
func (t *ZkTrie) TryGetNode(nodeHash *zkt.Hash) (*zktrie.Node, error) {
|
|
||||||
if bytes.Equal(nodeHash[:], zkt.HashZero[:]) {
|
|
||||||
return zktrie.NewEmptyNode(), nil
|
|
||||||
}
|
|
||||||
nBytes, err := t.db.Get(nodeHash[:])
|
|
||||||
if err == zktrie.ErrKeyNotFound {
|
|
||||||
return nil, zktrie.ErrKeyNotFound
|
|
||||||
} else if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return zktrie.NewNodeFromBytes(nBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProofTracer struct {
|
type ProofTracer struct {
|
||||||
*ZkTrie
|
*ZkTrie
|
||||||
deletionTracer map[zkt.Hash]struct{}
|
deletionTracer map[zkt.Hash]struct{}
|
||||||
|
|
@ -95,7 +80,7 @@ func (t *ProofTracer) GetDeletionProofs() ([][]byte, error) {
|
||||||
siblingHash = n.ChildL
|
siblingHash = n.ChildL
|
||||||
}
|
}
|
||||||
if siblingHash != nil {
|
if siblingHash != nil {
|
||||||
sibling, err := t.TryGetNode(siblingHash)
|
sibling, err := t.ZkTrie.Tree().GetNode(siblingHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue