# Inclusion proofs

> Prove that a block, and therefore every transfer in it, is part of the signed log.

An inclusion proof shows that a particular leaf is in a tree with a particular root, using only a handful of hashes instead of the whole tree. For a log of a million blocks, the proof is 20 hashes.

## Proving a transfer is in the log

:::steps
### Find its block
`GET /tx/:hash` gives the transfer's `block`.

### Check the block contains it
`GET /block/:height` lists the transfer hashes in `txs`. Recompute `txRoot` and the block `hash` as described in [Architecture](/network/architecture#block-structure) to confirm the block commits to your transfer.

### Get the proof
`GET /proof/inclusion/:height` returns the `leaf` (the block hash), the log `size`, the `root` and the audit `path`.

### Verify against a checkpoint
Check that `size` and `root` match a signed checkpoint, then run the RFC 9162 verification below. If it passes, the block is in the history that the checkpoint signs.
:::

## Verification

```js title="inclusion.mjs"
import { sha256 } from '@noble/hashes/sha2.js';

const hex = (s) => Uint8Array.from(s.match(/../g).map((b) => parseInt(b, 16)));
const toHex = (u) => [...u].map((b) => b.toString(16).padStart(2, '0')).join('');
const cat = (...a) => { const o = new Uint8Array(a.reduce((n, x) => n + x.length, 0)); let i = 0; for (const x of a) { o.set(x, i); i += x.length; } return o; };
const leafHash = (d) => sha256(cat(new Uint8Array([0]), d));
const nodeHash = (l, r) => sha256(cat(new Uint8Array([1]), l, r));

// RFC 9162, section 2.1.3.2
export function verifyInclusion(index, size, leaf, path, root) {
  if (index >= size) return false;
  let fn = index, sn = size - 1, r = leafHash(hex(leaf));
  for (const p of path.map(hex)) {
    if (sn === 0) return false;
    if (fn & 1 || fn === sn) {
      r = nodeHash(p, r);
      if (!(fn & 1)) while (!(fn & 1) && fn !== 0) { fn >>= 1; sn >>= 1; }
    } else r = nodeHash(r, p);
    fn >>= 1; sn >>= 1;
  }
  return sn === 0 && toHex(r) === root;
}
```

The explorer runs the same check in your browser at [usd.net/explorer/verify](https://usd.net/explorer/verify).
