Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bogdan-rosianu opened this issue Mar 22, 2024 · 2 comments
Assignees

Comments

@bogdan-rosianu
Copy link

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.

@gabrocheleau
Copy link
Contributor

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

Will take a look and report back.

@gabrocheleau
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants