mirror of https://github.com/status-im/nim-eth.git
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:
parent
9511502273
commit
cc6d88962e
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue