paritytech / paritytech/trie

Clarification on MPT Proof Structure and Node Encoding

Open
#220 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
274
Forks
72
PR merge metrics
No merged PRs in 30d

Description

Hi,

I am working with the trie-db crate and have been generating Merkle-Patricia Trie (MPT) proofs using the generate_proof function. I encountered a proof output that looks like this:

proof = [
    [128, 109, 246, 128, 40, 4, 143, 29, 173, 116, 217, 15, 202, 4, 160, 160, 243, 45, 95, 110, 28, 10, 153, 210, 113, 15, 3, 179, 233, 147, 5, 230, 153, 209, 209, 115, 128, 113, 191, 84, 118, 196, 215, 54, 25, 245, 52, 166, 200, 120, 122, 192, 104, 97, 253, 158, 24, 160, 177, 164, 114, 199, 9, 134, 60, 181, 222, 73, 243, 128, 136, 241, 139, 11, 150, 112, 108, 214, 87, 218, 133, 54, 61, 148, 207, 31, 88, 253, 222, 179, 177, 188, 198, 2, 133, 37, 168, 62, 129, 114, 253, 70, 128, 7, 163, 189, 250, 136, 142, 195, 195, 218, 59, 238, 243, 80, 253, 40, 152, 129, 165, 178, 131, 84, 196, 240, 8, 153, 237, 215, 189, 219, 47, 245, 58, 128, 11, 205, 1, 140, 183, 171, 19, 47, 147, 84, 153, 120, 73, 28, 170, 198, 246, 78, 95, 231, 36, 245, 98, 230, 117, 179, 163, 83, 179, 251, 184, 64, 0, 128, 48, 211, 8, 232, 219, 71, 172, 102, 249, 135, 136, 147, 93, 36, 70, 176, 85, 77, 95, 80, 246, 11, 121, 225, 79, 70, 115, 223, 48, 221, 117, 129, 128, 11, 242, 134, 219, 251, 72, 136, 31, 143, 118, 204, 30, 82, 119, 15, 192, 71, 77, 87, 3, 107, 161, 162, 237, 75, 19, 210, 7, 42, 15, 242, 195, 128, 9, 254, 94, 221, 144, 61, 92, 14, 157, 39, 103, 206, 173, 229, 219, 72, 95, 128, 151, 203, 214, 134, 216, 182, 96, 86, 108, 200, 86, 214, 110, 19, 128, 36, 255, 147, 74, 29, 85, 43, 167, 7, 132, 117, 60, 77, 200, 129, 26, 110, 25, 31, 16, 153, 7, 223, 150, 157, 184, 196, 37, 103, 57, 62, 105, 128, 175, 47, 204, 105, 72, 112, 255, 4, 235, 59, 5, 241, 155, 67, 73, 40, 194, 149, 151, 243, 142, 118, 139, 128, 140, 86, 180, 199, 167, 216, 121, 56],
    [128, 9, 0, 0, 128, 36, 25, 119, 113, 142, 246, 194, 73, 178, 154, 190, 114, 81, 232, 29, 114, 221, 10, 219, 104, 242, 170, 181, 114, 11, 19, 82, 255, 88, 163, 179, 197],
    [129, 5, 8, 32, 128, 152, 165, 197, 189, 19, 246, 122, 169, 52, 148, 27, 239, 143, 45, 182, 20, 157, 237, 67, 252, 163, 157, 162, 215, 192, 118, 168, 126, 248, 132, 182, 89, 0],
    [124, 101, 29, 221, 150, 105, 99, 28, 218, 101, 196, 107, 225, 80, 95, 11, 189, 109, 181, 202, 69, 33, 248, 233, 106, 239, 33, 148, 86, 180, 20, 0]
]

I understand that each Vec<u8> probably represents an encoded trie node, but I'm having trouble interpreting the structure and meaning of each node in the proof. I'm trying to understand:

  • The type of each node (e.g., branch, extension, leaf).
  • How these nodes collectively represent a proof of inclusion or exclusion for a particular key.

Could you please provide guidance or documentation on how to decode and interpret these proof nodes/values?

Thank you for your help!

(Mention to be pinged: @algomaster99, @javierron)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the trie-db crate's generate_proof function and follow the node-encoding implementation to identify how each Vec is serialized. Compare the generated proof with its target key to document node types and how the sequence establishes inclusion or exclusion. Done when the encoding and proof traversal are explained with a concrete decoding example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
databases, documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.