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
- 1
Find its block
GET /tx/:hashgives the transfer'sblock. - 2
Check the block contains it
GET /block/:heightlists the transfer hashes intxs. RecomputetxRootand the blockhashas described in Architecture to confirm the block commits to your transfer. - 3
Get the proof
GET /proof/inclusion/:heightreturns theleaf(the block hash), the logsize, therootand the auditpath. - 4
Verify against a checkpoint
Check that
sizeandrootmatch a signed checkpoint, then run the RFC 9162 verification below. If it passes, the block is in the history that the checkpoint signs.
Verification
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.