ethereumjs-monorepo icon indicating copy to clipboard operation
ethereumjs-monorepo copied to clipboard

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

Open bogdan-rosianu opened this issue 1 year ago • 1 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.

bogdan-rosianu avatar Mar 22 '24 14:03 bogdan-rosianu

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

Will take a look and report back.

gabrocheleau avatar Apr 23 '24 01:04 gabrocheleau

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.

gabrocheleau avatar Apr 28 '24 20:04 gabrocheleau

Hi @bogdan-rosianu, just to let you know: we have a very very late release round this time - since we had (close to) no release pressure - so that issues like this only get in now (or: in 1-2 weeks on release). 😬

Apologies!

holgerd77 avatar Aug 12 '24 06:08 holgerd77