mpt: disallow empty keys

This is not a problem in practice, as all keys are prefixed
by a contract ID. However in theory it can lead to a different
state root after new portion of changes thus this fix.
This commit is contained in:
Evgeniy Stratonikov 2021-06-03 15:46:35 +03:00
parent 5b1f6207de
commit e833d333fe
3 changed files with 16 additions and 15 deletions

View file

@ -97,7 +97,9 @@ func (t *Trie) getWithPath(curr Node, path []byte) (Node, []byte, error) {
// Put puts key-value pair in t.
func (t *Trie) Put(key, value []byte) error {
if len(key) > MaxKeyLength {
if len(key) == 0 {
return errors.New("key is empty")
} else if len(key) > MaxKeyLength {
return errors.New("key is too big")
} else if len(value) > MaxValueLength {
return errors.New("value is too big")