0xPolygonZero / eth-trie-tools

Various debugging tools for working with tries for `eth_trie_utils`.
1 stars 2 forks source link

Decode RLP values in TrieDiff output #9

Open Nashtare opened 4 months ago

Nashtare commented 4 months ago

The trie diff tool will output something like this currently (added formatting for readability)

Point Diff {
    depth: 0,
    Path: (Branch(12) --> Branch(13) --> Branch(1) --> Branch(1) --> Branch(8) --> Branch(7) --> Branch(14) --> Branch(14) --> Branch(12)),
    Key: 0xcd1187eec,
    A info: (
        key: 0xcd1187eec83bc100b4e63e815deeba81810d9d6921d7ad3f4b987440c84ea666,
        Value: "f8440180a046436918d517d18028d2e44a47022f16d4f349d1c58284f1d3bda3305d18ea41a0516e38ed2cd77bcb4dfb71f1afe70b0516eeb781a30e5c770fbee39aa6eb809c",
        Node type: Leaf Trie,
        hash: 9b594f92cd023c5d8f9b3a9f513faa1abc709b824ede7d3712b28ea6ed6c3510
    ),
    B info: (
        key: 0xcd1187eec83bc100b4e63e815deeba81810d9d6921d7ad3f4b987440c84ea666,
        Value: "f8440180a0746b7a0278ae1126808f786cadf431f73a18b7deda4c7543ba82f0e75a73fa2ea0516e38ed2cd77bcb4dfb71f1afe70b0516eeb781a30e5c770fbee39aa6eb809c",
        Node type: Leaf Trie,
        hash: 44e8d85eb8b9becc4c45d91ea8e7c3110a77bba6628aba4362eba01bd390d5ad
    )
}

It would be nice if it was displaying the Decoded value along with the currently Encoded value, which in this case could look like:

Point Diff {
    depth: 0,
    Path: (Branch(12) --> Branch(13) --> Branch(1) --> Branch(1) --> Branch(8) --> Branch(7) --> Branch(14) --> Branch(14) --> Branch(12)),
    Key: 0xcd1187eec,
    A info: (
        key: 0xcd1187eec83bc100b4e63e815deeba81810d9d6921d7ad3f4b987440c84ea666,
        Encoded value: "f8440180a046436918d517d18028d2e44a47022f16d4f349d1c58284f1d3bda3305d18ea41a0516e38ed2cd77bcb4dfb71f1afe70b0516eeb781a30e5c770fbee39aa6eb809c",
        Decoded value: AccountRlp {
            nonce: 1,
            balance: 0,
            storage_root: 0x46436918d517d18028d2e44a47022f16d4f349d1c58284f1d3bda3305d18ea41,
            code_hash: 0x516e38ed2cd77bcb4dfb71f1afe70b0516eeb781a30e5c770fbee39aa6eb809c
        },
        Node type: Leaf Trie,
        hash: 9b594f92cd023c5d8f9b3a9f513faa1abc709b824ede7d3712b28ea6ed6c3510
    ),
    B info: (
        key: 0xcd1187eec83bc100b4e63e815deeba81810d9d6921d7ad3f4b987440c84ea666,
        Encoded Value: "f8440180a0746b7a0278ae1126808f786cadf431f73a18b7deda4c7543ba82f0e75a73fa2ea0516e38ed2cd77bcb4dfb71f1afe70b0516eeb781a30e5c770fbee39aa6eb809c",
        Decoded value: AccountRlp {
            nonce: 1,
            balance: 0,
            storage_root: 0x746b7a0278ae1126808f786cadf431f73a18b7deda4c7543ba82f0e75a73fa2e,
            code_hash: 0x516e38ed2cd77bcb4dfb71f1afe70b0516eeb781a30e5c770fbee39aa6eb809c
        },
        Node type: Leaf Trie,
        hash: 44e8d85eb8b9becc4c45d91ea8e7c3110a77bba6628aba4362eba01bd390d5ad
    )
}
BGluth commented 3 months ago

Hmm... So the idea would be to try and decode to AccountRlp or an rlped storage value and display that if it's successful right?

Nashtare commented 3 months ago

Yeah. Could also be decoding the txn or the receipt if we need to debug those tries (though rarely happens). Does that seem worth it to you?

BGluth commented 3 months ago

Yeah this seems like a nice-to-have and should be pretty trivial to implement (just four decode attempts). The only potential issue that I see is we could mis-decode some non-evm trie value into a storage trie slot, just since the value type is rlp(U256), but I don't think that this probably really matters that much.