aboutsummaryrefslogtreecommitdiffstats
path: root/trie
diff options
context:
space:
mode:
authorgary rong <garyrong0905@gmail.com>2019-05-07 20:06:07 +0800
committerPéter Szilágyi <peterke@gmail.com>2019-05-07 20:06:07 +0800
commit14868a37fb73164205e78ecf37bc3fe2e6084c6d (patch)
treeecbd9f09bd99dfe7e702b467ec50e19c9279c589 /trie
parentabeba0a1de8e276255beba46b048627a4f529720 (diff)
downloadgo-tangerine-14868a37fb73164205e78ecf37bc3fe2e6084c6d.tar
go-tangerine-14868a37fb73164205e78ecf37bc3fe2e6084c6d.tar.gz
go-tangerine-14868a37fb73164205e78ecf37bc3fe2e6084c6d.tar.bz2
go-tangerine-14868a37fb73164205e78ecf37bc3fe2e6084c6d.tar.lz
go-tangerine-14868a37fb73164205e78ecf37bc3fe2e6084c6d.tar.xz
go-tangerine-14868a37fb73164205e78ecf37bc3fe2e6084c6d.tar.zst
go-tangerine-14868a37fb73164205e78ecf37bc3fe2e6084c6d.zip
trie: clarify why verifyProof doesn't check hashes (#19530)
* trie: fix merkle proof * trie: use hasher instead of allocate keccack256 every time * trie: add comments
Diffstat (limited to 'trie')
-rw-r--r--trie/proof.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/trie/proof.go b/trie/proof.go
index 26a41ed27..3c4b8d653 100644
--- a/trie/proof.go
+++ b/trie/proof.go
@@ -21,7 +21,6 @@ import (
"fmt"
"github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
@@ -81,7 +80,7 @@ func (t *Trie) Prove(key []byte, fromLevel uint, proofDb ethdb.Writer) error {
} else {
enc, _ := rlp.EncodeToBytes(n)
if !ok {
- hash = crypto.Keccak256(enc)
+ hash = hasher.makeHashNode(enc)
}
proofDb.Put(hash, enc)
}
@@ -104,6 +103,8 @@ func (t *SecureTrie) Prove(key []byte, fromLevel uint, proofDb ethdb.Writer) err
// VerifyProof checks merkle proofs. The given proof must contain the value for
// key in a trie with the given root hash. VerifyProof returns an error if the
// proof contains invalid trie nodes or the wrong value.
+//
+// Note, the method assumes that all key-values in proofDb satisfy key = hash(value).
func VerifyProof(rootHash common.Hash, key []byte, proofDb ethdb.Reader) (value []byte, nodes int, err error) {
key = keybytesToHex(key)
wantHash := rootHash