Skip to content

Commit 14868a3

Browse files
rjl493456442karalabe
authored andcommitted
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
1 parent abeba0a commit 14868a3

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎trie/proof.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222

2323
"github.com/ethereum/go-ethereum/common"
24-
"github.com/ethereum/go-ethereum/crypto"
2524
"github.com/ethereum/go-ethereum/ethdb"
2625
"github.com/ethereum/go-ethereum/log"
2726
"github.com/ethereum/go-ethereum/rlp"
@@ -81,7 +80,7 @@ func (t *Trie) Prove(key []byte, fromLevel uint, proofDb ethdb.Writer) error {
8180
} else {
8281
enc, _ := rlp.EncodeToBytes(n)
8382
if !ok {
84-
hash = crypto.Keccak256(enc)
83+
hash = hasher.makeHashNode(enc)
8584
}
8685
proofDb.Put(hash, enc)
8786
}
@@ -104,6 +103,8 @@ func (t *SecureTrie) Prove(key []byte, fromLevel uint, proofDb ethdb.Writer) err
104103
// VerifyProof checks merkle proofs. The given proof must contain the value for
105104
// key in a trie with the given root hash. VerifyProof returns an error if the
106105
// proof contains invalid trie nodes or the wrong value.
106+
//
107+
// Note, the method assumes that all key-values in proofDb satisfy key = hash(value).
107108
func VerifyProof(rootHash common.Hash, key []byte, proofDb ethdb.Reader) (value []byte, nodes int, err error) {
108109
key = keybytesToHex(key)
109110
wantHash := rootHash

0 commit comments

Comments
 (0)