trie: don't crash for invalid proof (needs investigation)

This commit is contained in:
Felix Lange 2017-06-15 19:07:41 +02:00
parent cc860e38e5
commit df0056c1dc

View file

@ -125,7 +125,7 @@ func VerifyProof(rootHash common.Hash, key []byte, proof []rlp.RawValue) (value
} }
func get(tn node, key []byte) ([]byte, node) { func get(tn node, key []byte) ([]byte, node) {
for len(key) > 0 { for {
switch n := tn.(type) { switch n := tn.(type) {
case *shortNode: case *shortNode:
if len(key) < len(n.Key) || !bytes.Equal(n.Key, key[:len(n.Key)]) { if len(key) < len(n.Key) || !bytes.Equal(n.Key, key[:len(n.Key)]) {
@ -140,9 +140,10 @@ func get(tn node, key []byte) ([]byte, node) {
return key, n return key, n
case nil: case nil:
return key, nil return key, nil
case valueNode:
return nil, n
default: default:
panic(fmt.Sprintf("%T: invalid node: %v", tn, tn)) panic(fmt.Sprintf("%T: invalid node: %v", tn, tn))
} }
} }
return nil, tn.(valueNode)
} }