paritytech / trie

Base-16 Modified Patricia Merkle Tree (aka Trie)
Apache License 2.0
258 stars 67 forks source link

Trie-db lookup fails to find value in db after trie commit when using Ethereum RLP node codec. #205

Closed 0xkr8os closed 1 year ago

0xkr8os commented 1 year ago

Hey team, I've been banging my head trying to get proofs generated for Ethereum RLP leaf nodes. I've created a custom trie layout that specifies the Ethereum rlp node codec. I'm using the generate proof function in the trie-eip1186 module. I am able to successfully insert entries and retrieve them within the same scope but once the trie drops out of scope, I cannot retrieve the inserted entry.

I noticed the encoded root node value in the db after the trie.commit contains the value I just inserted but for some reason, the key does not retrieve it.

hashed_key = 798c6047767c10f653ca157a7f66a592a1d6ca550cae352912be0b0745336af

rlp_encoded_value = f8440180a00f460850d9716af3371839ff600d3d57ce12da330e95ac16f91da485fd8bd6c6a01e1706bdc2b9de10c4075b84a6181920bb73d94a161cb8044fc5d1c800030627

encoded_root_node = f869a0798c6047767c10f653ca157a7f66a592a1d6ca550cae352912be0b0745336afdb846f8440180a00f460850d9716af3371839ff600d3d57ce12da330e95ac16f91da485fd8bd6c6a01e1706bdc2b9de10c4075b84a6181920bb73d94a161cb8044fc5d1c800030627

I've noticed several issues and threads about this and no one seems to have the complete solution. I know the go-ethereum project has this working but it's using an ancient version of triedb. I feel like I'm super close and would love to publish a working example once it's working. Any help on this would be greatly appreciated. 🙏🏼

0xkr8os commented 1 year ago

Found the culprit. The nibble slice offset was off by 1. On lookup, the partial nibble slice defaults to 0 and the slice from my rlp node codec was returning 1. We up.