From 85928027c7f3890414d197150d49fcca4f178279 Mon Sep 17 00:00:00 2001 From: bhartnett Date: Fri, 22 Aug 2025 15:18:44 +0800 Subject: [PATCH 1/3] Fix rlp encoding of HashKey type. --- execution_chain/db/aristo/aristo_desc/desc_identifiers.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/execution_chain/db/aristo/aristo_desc/desc_identifiers.nim b/execution_chain/db/aristo/aristo_desc/desc_identifiers.nim index 83a5095f0f..8c3a2ca887 100644 --- a/execution_chain/db/aristo/aristo_desc/desc_identifiers.nim +++ b/execution_chain/db/aristo/aristo_desc/desc_identifiers.nim @@ -218,7 +218,7 @@ func hash*(a: HashKey): Hash = func append*(w: var RlpWriter; key: HashKey) = if 1 < key.len and key.len < 32: - w.appendRawBytes key.data + w.writeBlob key.data else: w.append key.data From dc205271a22541ece5568425eeffb107fc491ebb Mon Sep 17 00:00:00 2001 From: bhartnett Date: Wed, 27 Aug 2025 11:19:37 +0800 Subject: [PATCH 2/3] Add test which covers trie root calculations for embedded trie node in HashKey scenario. --- tests/test_ledger.nim | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test_ledger.nim b/tests/test_ledger.nim index fa88dbf9c7..a37cff3d00 100644 --- a/tests/test_ledger.nim +++ b/tests/test_ledger.nim @@ -814,6 +814,31 @@ proc runLedgerBasicOperationsTests() = ac.clearBlockHashesCache() check ac.getBlockHashesCache().len() == 0 + test "Verify stateRoot and storageRoot for large storage trie": + # We use a small slot value and a large number of iterations so that + # the test also covers the scenario when the HashKey type contains + # an embedded trie node (when the data length is less than 32 bytes) which, + # when rlp encoded impacts the stateRoot and storageRoot calculation. + const + iterations = 110000 + address = Address.fromHex("0x123456cf1046e68e36E1aA2E0E07105eDDD1f08E") + slotValue = u256(1) + + let + coreDb = newCoreDbRef(DefaultDbMemory) + ledger = LedgerRef.init(coreDb.baseTxFrame()) + + for i in 1..iterations: + ledger.setStorage(address, u256(i), slotValue) + ledger.persist() + + let + stateRoot = ledger.getStateRoot() + storageRoot = ledger.getStorageRoot(address) + check: + stateRoot == Hash32.fromHex("0xc70266a02ed1531d8e2c47c7ead2a6e8b1f01bf7dbee3b36f8d5dc543ad09658") + storageRoot == Hash32.fromHex("0x619034bd7de60f9f8a08cdf277dc55da1984aae08c79e190faeafba27bc3c9d2") + # ------------------------------------------------------------------------------ # Main function(s) # ------------------------------------------------------------------------------ From b254482c0ba2ea64e2888362f5be191fd23c09df Mon Sep 17 00:00:00 2001 From: bhartnett Date: Wed, 27 Aug 2025 11:20:34 +0800 Subject: [PATCH 3/3] Revert change to Hashkey type. --- execution_chain/db/aristo/aristo_desc/desc_identifiers.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/execution_chain/db/aristo/aristo_desc/desc_identifiers.nim b/execution_chain/db/aristo/aristo_desc/desc_identifiers.nim index 8c3a2ca887..83a5095f0f 100644 --- a/execution_chain/db/aristo/aristo_desc/desc_identifiers.nim +++ b/execution_chain/db/aristo/aristo_desc/desc_identifiers.nim @@ -218,7 +218,7 @@ func hash*(a: HashKey): Hash = func append*(w: var RlpWriter; key: HashKey) = if 1 < key.len and key.len < 32: - w.writeBlob key.data + w.appendRawBytes key.data else: w.append key.data