Skip to content

Commit

Permalink
test to compare the proof format with that of rust verkle (ethereum#73)
Browse files Browse the repository at this point in the history
* test to compare the proof format with that of rust verkle

* comment block extraction code
  • Loading branch information
gballet authored Feb 8, 2022
1 parent e8114e8 commit 2ac6b86
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 10 deletions.
21 changes: 11 additions & 10 deletions core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
package core

import (
"bytes"
//"bytes"
"crypto/ecdsa"
"fmt"
//"fmt"
"math/big"
"os"
//"os"
"testing"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -34,7 +34,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
//"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
"golang.org/x/crypto/sha3"
)
Expand Down Expand Up @@ -394,12 +394,13 @@ func TestProcessStateless(t *testing.T) {
gen.AddTx(tx)
})

f, _ := os.Create("block2.rlp")
defer f.Close()
var buf bytes.Buffer
rlp.Encode(&buf, chain[1])
f.Write(buf.Bytes())
fmt.Printf("%x\n", chain[0].Root())
// Uncomment to extract block #2
//f, _ := os.Create("block2.rlp")
//defer f.Close()
//var buf bytes.Buffer
//rlp.Encode(&buf, chain[1])
//f.Write(buf.Bytes())
//fmt.Printf("root= %x\n", chain[0].Root())

_, err := blockchain.InsertChain(chain)
if err != nil {
Expand Down
86 changes: 86 additions & 0 deletions trie/verkle_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright 2021 go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

package trie

import (
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/gballet/go-verkle"
)

func TestReproduceTree(t *testing.T) {
presentKeys := [][]byte{
common.Hex2Bytes("318dea512b6f3237a2d4763cf49bf26de3b617fb0cabe38a97807a5549df4d01"),
common.Hex2Bytes("e6ed6c222e3985050b4fc574b136b0a42c63538e9ab970995cd418ba8e526400"),
common.Hex2Bytes("18fb432d3b859ec3a1803854e8cceea75d092e52d0d4a4398d13022496745a02"),
common.Hex2Bytes("318dea512b6f3237a2d4763cf49bf26de3b617fb0cabe38a97807a5549df4d02"),
common.Hex2Bytes("18fb432d3b859ec3a1803854e8cceea75d092e52d0d4a4398d13022496745a04"),
common.Hex2Bytes("e6ed6c222e3985050b4fc574b136b0a42c63538e9ab970995cd418ba8e526402"),
common.Hex2Bytes("e6ed6c222e3985050b4fc574b136b0a42c63538e9ab970995cd418ba8e526403"),
common.Hex2Bytes("18fb432d3b859ec3a1803854e8cceea75d092e52d0d4a4398d13022496745a00"),
common.Hex2Bytes("18fb432d3b859ec3a1803854e8cceea75d092e52d0d4a4398d13022496745a03"),
common.Hex2Bytes("e6ed6c222e3985050b4fc574b136b0a42c63538e9ab970995cd418ba8e526401"),
common.Hex2Bytes("e6ed6c222e3985050b4fc574b136b0a42c63538e9ab970995cd418ba8e526404"),
common.Hex2Bytes("318dea512b6f3237a2d4763cf49bf26de3b617fb0cabe38a97807a5549df4d00"),
common.Hex2Bytes("18fb432d3b859ec3a1803854e8cceea75d092e52d0d4a4398d13022496745a01"),
}

absentKeys := [][]byte{
common.Hex2Bytes("318dea512b6f3237a2d4763cf49bf26de3b617fb0cabe38a97807a5549df4d03"),
common.Hex2Bytes("318dea512b6f3237a2d4763cf49bf26de3b617fb0cabe38a97807a5549df4d04"),
}

values := [][]byte{
common.Hex2Bytes("320122e8584be00d000000000000000000000000000000000000000000000000"),
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000"),
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000"),
common.Hex2Bytes("0300000000000000000000000000000000000000000000000000000000000000"),
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000"),
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000"),
common.Hex2Bytes("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"),
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000"),
common.Hex2Bytes("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"),
common.Hex2Bytes("1bc176f2790c91e6000000000000000000000000000000000000000000000000"),
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000"),
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000"),
common.Hex2Bytes("e703000000000000000000000000000000000000000000000000000000000000"),
}

root := verkle.New()
kv := make(map[string][]byte)

for i, key := range presentKeys {
root.Insert(key, values[i], nil)
kv[string(key)] = values[i]
}

proof, Cs, zis, yis := verkle.MakeVerkleMultiProof(root, append(presentKeys, absentKeys...), kv)
verkle.VerifyVerkleProof(proof, Cs, zis, yis, verkle.GetConfig())

t.Log("commitments returned by proof:")
for i, c := range Cs {
t.Logf("%d %x", i, c.Bytes())
}

p, _, err := verkle.SerializeProof(proof)
if err != nil {
t.Fatal(err)
}
t.Logf("serialized: %x", p)
t.Logf("tree: %s", verkle.ToDot(root))
}

0 comments on commit 2ac6b86

Please sign in to comment.