Skip to content

Check for root in EncodeAndHash #2357

@kishansagathiya

Description

@kishansagathiya

Issue summary

  • Looking at the comments and code, trie.Hash() and trie.root.EncodeAndHash() should produce the same hash, but they don't. condition of len(key) < 32 is not checked in trie.Hash and it hashes everything, because in case of root nodes we are supposed to return hash of encoding as hash regardless of length of encoding. This creates mismatching hashes from both functions.

  • Right now the logic used in node.EncodeAndHash() is repeating in trie.Hash.

  • trie.Hash should get hash from trie.RootNode.EncodeAndHash() and return it

  • In node.EncodeAndHash we should check if this node is root or not. If the node is root we should return blake2b hash of its encoding regardless of length of its encoding.

  • And then, trie.Hash should get hash from trie.RootNode.EncodeAndHash() and return it.

Other information and links

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions