Treat putting empty data in hexary trie as deleting data (#720)

Other implementations of MPT delete entries when attempting to put empty
value, because empty value cannot exist in RLP. We should match the
behaviour.

- https://github.com/ethereum/py-trie/pull/109

Also cross-checked with Geth and Ethereumjs implementations.
This commit is contained in:
Etan Kissling 2024-08-15 01:48:39 +02:00 committed by GitHub
parent 9511502273
commit cc6d88962e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 0 deletions

View File

@ -653,6 +653,12 @@ proc mergeAt(self: var HexaryTrie, orig: Rlp, origHash: KeccakHash,
return r.finish return r.finish
proc put*(self: var HexaryTrie; key, value: openArray[byte]) = proc put*(self: var HexaryTrie; key, value: openArray[byte]) =
if value.len == 0:
# Empty nodes are not allowed as `[]` is not a valid RLP encoding
# https://github.com/ethereum/py-trie/pull/109
self.del key
return
let root = self.root.hash let root = self.root.hash
var rootBytes = self.db.get(root.data) var rootBytes = self.db.get(root.data)