diff --git a/trie/proof.go b/trie/proof.go index 7ce76f8c89..9611b5a3e8 100644 --- a/trie/proof.go +++ b/trie/proof.go @@ -264,11 +264,13 @@ func unset(root node, rest []byte, removeLeft bool) { unset(rn.Children[rest[0]], rest[1:], removeLeft) case *shortNode: rn.flags = nodeFlag{dirty: true} + if _, ok := rn.Val.(valueNode); ok { + rn.Val = nil + return + } unset(rn.Val, rest[len(rn.Key):], removeLeft) - case hashNode, nil: + case hashNode, nil, valueNode: panic("it shouldn't happen") - case valueNode: - return } } diff --git a/trie/proof_test.go b/trie/proof_test.go index 2cb5154dc2..17e7a41a5a 100644 --- a/trie/proof_test.go +++ b/trie/proof_test.go @@ -164,7 +164,7 @@ func TestBadRangeProof(t *testing.T) { keys = append(keys, entries[i].k) vals = append(vals, entries[i].v) } - testcase := mrand.Intn(4) + testcase := mrand.Intn(6) var index int switch testcase { case 0: @@ -188,6 +188,14 @@ func TestBadRangeProof(t *testing.T) { index = mrand.Intn(end - start) keys[index] = entries[len(entries)-1].k vals[index] = entries[len(entries)-1].v + case 4: + // Set random key to nil + index = mrand.Intn(end - start) + keys[index] = nil + case 5: + // Set random value to nil + index = mrand.Intn(end - start) + vals[index] = nil } err := VerifyRangeProof(trie.Hash(), keys, vals, firstProof, lastProof) if err == nil {