From cc6d88962e4a22170361b576534246bd57974d80 Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Thu, 15 Aug 2024 01:48:39 +0200 Subject: [PATCH] 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. --- eth/trie/hexary.nim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/eth/trie/hexary.nim b/eth/trie/hexary.nim index ec9f638..2144111 100644 --- a/eth/trie/hexary.nim +++ b/eth/trie/hexary.nim @@ -653,6 +653,12 @@ proc mergeAt(self: var HexaryTrie, orig: Rlp, origHash: KeccakHash, return r.finish 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 var rootBytes = self.db.get(root.data)