ethereumjs / ethereumjs-monorepo

Monorepo for the Ethereum VM TypeScript Implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

'Error: Uint8Array expected' when trying to delete from a trie with 'useNodePruning' enabled

bogdan-rosianu opened this issue · comments

package.json: "@ethereumjs/trie": "^6.2.0",

I have isolated the issue within an unit test:

it("test trie deletion", async () => {
    const trie = new Trie({ db: new MapDB(), useRootPersistence: true, useNodePruning: true });
    
    await trie.put(utf8ToBytes("key1"), utf8ToBytes("value1"));
    await trie.put(utf8ToBytes("key2"), utf8ToBytes("value2"));
    await trie.del(utf8ToBytes("key1"));
    expect(bytesToHex(trie.root())).toBe("0x9fabdc1cccb1e3a1fa5d991a12087b54360ea47811b36acc1193e2d9ede0cdef");
  });

This will fail when trying to delete with this error:

Error: Uint8Array expected

    at bytesToHex (.../node_modules/@noble/hashes/src/utils.ts:49:30)
    at .../node_modules/@ethereumjs/trie/src/db/checkpoint.ts:247:36
    at Array.map (<anonymous>)
    at CheckpointDB.batch (.../node_modules/@ethereumjs/trie/src/db/checkpoint.ts:240:36)
    at Trie.saveStack (.../node_modules/@ethereumjs/trie/src/trie.ts:1079:20)
    at Trie._deleteNode (.../node_modules/@ethereumjs/trie/src/trie.ts:1033:18)

Switching to useNodePruning: false fixes this issue.

Not sure if expected or not.

Thanks for creating the issue and coming up with a test case!

Will take a look and report back.

Hi @bogdan-rosianu

The issue has been addressed by #3378, which should be reviewed and merged in shortly. Thanks a lot for uncovering it and coming up with a straightforward reproduction test case. We will be adding your test case to the monorepo as well.