Cryptographic Proofs and State Reconstruction

← Back to SHAMap and NodeStore: Data Persistence and State Management


Introduction

The combination of SHAMap and NodeStore provides more than just efficient storage—they enable cryptographic proofs that transactions were executed correctly and state was computed honestly.

This chapter explores:

  • Merkle proof generation and verification

  • State reconstruction from transaction history

  • Cross-chain or light-client verification

  • The guarantee of verifiable ledger history

Merkle Proof Generation

A Merkle proof allows someone to verify that data is in a tree without reconstructing the entire tree.

Algorithm: getProofPath

std::optional<std::vector<Blob>>
SHAMap::getProofPath(uint256 const& key)
{
    std::vector<Blob> path;

    auto node = std::dynamic_pointer_cast<SHAMapInnerNode>(mRoot);

    for (int depth = 0; depth < 64; ++depth) {
        // Serialize current node
        Blob serialized = node->serialize();
        path.push_back(serialized);

        // Is this the target leaf?
        if (auto leaf = std::dynamic_pointer_cast<SHAMapLeafNode>(node)) {
            if (leaf->getKey() == key) {
                return path;  // Success
            } else {
                return std::nullopt;  // Wrong leaf
            }
        }

        // Navigate to next level
        int branch = key.nthNibble(depth);
        node = std::dynamic_pointer_cast<SHAMapInnerNode>(
            node->getChild(branch));

        if (!node) {
            return std::nullopt;  // Path doesn't exist
        }
    }

    return std::nullopt;  // Shouldn't reach here
}

Example Proof:

For an account with key 0x3A7F2E1B...:

Proof Size Properties:

Proof Verification

Verifying a proof requires only the root hash and the proof:

Algorithm: verifyProofPath

Verification Process:

Proof Use Cases

1. Light Clients

2. Cross-Chain Bridges

3. Auditing and Compliance

4. Rollups and Scaling

State Reconstruction Guarantee

The transaction tree provides a critical guarantee: verifiable unique history.

The Problem Without Transaction Tree:

The Solution: Transaction Tree

The XRP Ledger maintains both trees in every ledger:

State Reconstruction:

Why This Matters:

Ledger Verifiability

Every aspect of XRPL state is cryptographically verifiable:

Account Proof

Transaction Proof

Full Ledger Proof

Practical Verification Workflow

Step 1: Trust the Ledger Header

Step 2: Request Proof

Step 3: Verify Proof

Step 4: Use Verified Data

Summary

Key Concepts:

  1. Merkle Proofs: Logarithmic-sized proofs of inclusion

  2. Proof Verification: O(log N) hash checks to verify

  3. Light Clients: Verify without downloading full ledger

  4. Unique History: Transaction tree guarantees verifiable history

  5. Ledger Integrity: All state cryptographically provable

Security Properties:

Performance:

This is the power of Merkle trees applied to blockchain: trustless verification at scale.

Last updated