Skip to content

feat: Expose Root Computation from VerifyLeafHashes #290

@walldiss

Description

@walldiss

Feature Request: Expose Root Computation from VerifyLeafHashes

Description:
Currently, the VerifyLeafHashes function in the NMT library performs two operations internally:

  1. Computing the root from provided proof and data.
  2. Comparing the computed root with an existing root.

To facilitate use cases where root computation alone is required (without immediate comparison), we propose breaking down VerifyLeafHashes into two distinct functions. The main goal is to expose the root computation logic separately.

Proposed Change:

  • Extract root computation into a separate, publicly accessible function, e.g., ComputeRoot(proof, data).
  • Update VerifyLeafHashes to utilize this new function internally:
func ComputeRoot(proof Proof, data []byte) ([]byte, error) {
    // Existing logic from VerifyInclusion to compute root
}

func VerifyLeafHashes(proof Proof, data []byte, root []byte) (bool, error) {
    computedRoot, err := ComputeRoot(proof, data)
    if err != nil {
        return false, err
    }
    return bytes.Equal(root, computedRoot), nil
}

Benefits:

  • Allows consumers to recompute roots separately from verification, enabling more flexible use-cases and simplifying proofs.
  • Minimal change, reusing approximately 99% of existing code.

Impact:

  • Non-breaking change, backward-compatible.
  • Minor refactor only; no new logic introduced.

Feedback and suggestions are welcome.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions