Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing error checks for the root node type #214

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions trie/verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ func NewVerkleTrie(root verkle.VerkleNode, db *Database, pointCache *utils.Point
}
}

var errInvalidProof = errors.New("invalid proof")
var (
errInvalidProof = errors.New("invalid proof")
errInvalidRootType = errors.New("invalid node type for root")
)

// GetKey returns the sha3 preimage of a hashed key that was previously used
// to store a value.
Expand Down Expand Up @@ -81,7 +84,16 @@ func (t *VerkleTrie) TryGetAccount(key []byte) (*types.StateAccount, error) {
}
)
versionkey := t.pointCache.GetTreeKeyVersionCached(key)
values, err := t.root.(*verkle.InternalNode).GetStem(versionkey[:31], resolver)
var (
values [][]byte
err error
)
switch t.root.(type) {
case *verkle.InternalNode:
values, err = t.root.(*verkle.InternalNode).GetStem(versionkey[:31], resolver)
default:
return nil, errInvalidRootType
}
if err != nil {
return nil, fmt.Errorf("TryGetAccount (%x) error: %v", key, err)
}
Expand Down Expand Up @@ -136,6 +148,8 @@ func (t *VerkleTrie) TryUpdateAccount(key []byte, acc *types.StateAccount) error
switch root := t.root.(type) {
case *verkle.InternalNode:
err = root.InsertStem(stem, values, flusher)
default:
return errInvalidRootType
}
if err != nil {
return fmt.Errorf("TryUpdateAccount (%x) error: %v", key, err)
Expand Down Expand Up @@ -189,7 +203,7 @@ func (t *VerkleTrie) TryDeleteAccount(key []byte) error {
case *verkle.InternalNode:
err = root.InsertStem(stem, values, resolver)
default:
panic("invalid tree type")
return errInvalidRootType
}
if err != nil {
return fmt.Errorf("TryDeleteAccount (%x) error: %v", key, err)
Expand Down