pokt-network / pocket

Official implementation of the Pocket Network Protocol v1
https://pokt.network
MIT License
61 stars 33 forks source link

[Persistence] Change the state root hash computation mechanism #834

Closed h5law closed 1 year ago

h5law commented 1 year ago

Objective

The way the root hash is currently computed is as follows:

stateHash := sha256.Sum256(appTreeHash + transactionsTreeHash + ... + flagsTreeHash)

This requires the order of the sub tree hashes to be known in order to calculate the state hash, and therefore to prove the inclusion of a specific tree in the state hash calculation this order must be known throughout the codebase.

This should instead be as follows:

  1. Create a rootTree object in the TreeStore module
  2. Fill this tree with the following key-value pairings
    • "app": appTree.Root()
    • "transactions": transactionsTree.Root()
    • ...
  3. Calculate the overall state hash by rootTree.Root()

This allows for the computation of the state hash in a deterministic manner as the SMT is not order dependent in its updates, thus removing the need to know the tree orders as they are no longer needed. It also allows for the generation of proofs determining whether a state tree hash was included in the root hash - this will be needed for the IBC module's light clients.

Origin Document

Screenshot 2023-06-16 at 18 49 08 Screenshot 2023-06-16 at 18 49 41

Goals

Deliverable

Non-goals / Non-deliverables

General issue deliverables

Testing Methodology


Creator: @h5law Co-Owners: @dylanlott