0

I understand <> it is used for empty slots, rootHash is 16 for hex. and hashB placed 5th position because of '4', but how does perhaps padding work? i.e. in hashA: 20, hashB: 00, hashE: <17>, [<35>]

I read some existing solutions but not quite related to this problem. I hope you can help me.

Problem:

<64 6f> : 'verb'
<64 6f 67> : 'puppy'
<64 6f 67 65> : 'coin'
<68 6f 72 73 65> : 'stallion'

Answer:

rootHash: [ <16>, hashA ]
hashA:    [ <>, <>, <>, <>, hashB, <>, <>, <>, [ <20 6f 72 73 65>, 'stallion' ], <>, <>, <>, <>, <>, <>, <>, <> ]
hashB:    [ <00 6f>, hashD ]
hashD:    [ <>, <>, <>, <>, <>, <>, hashE, <>, <>, <>, <>, <>, <>, <>, <>, <>, 'verb' ]
hashE:    [ <17>, [ <>, <>, <>, <>, <>, <>, [ <35>, 'coin' ], <>, <>, <>, <>, <>, <>, <>, <>, <>, 'puppy' ] ]

src: https://ethereum.org/en/developers/docs/data-structures-and-encoding/patricia-merkle-trie/#example-trie

1 Answer 1

1

The answer is in this page too, just above the code you posted.

It is called COMPACT encoding, whose implementation located in go-ethereum/trie/encoding.go.

In hashA: 20, hashB: 00, hashE: <17>, [<35>], they have been handled by compact_encode function shown on the page too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.