code wiki / (root) / nx_bt_v2_merkle.nx

nx_bt_v2_merkle.nx

buildroot/runtime/nx_bt_v2_merkle.nx

3214 B60 linesdepth 5pulls 5 transitivereach 1 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_bt_v2_merkle.nx -- LIB: BitTorrent v2 (BEP 52) style SHA-256 MERKLE piece tree + INCLUSION PROOFS. Upgrades our torrents from v1 (SHA-1 flat piece list) to v2: each leaf = SHA-256 of a block, internal node = SHA-256(left||right), the root is the file's content hash (the basis for urn:btmh magnets). The killer feature is the inclusion PROOF: a peer can verify ONE block belongs to the root using only log2(n) sibling hashes -- verifiable random access / streaming, no need for the whole file. Composes nx_sha256 (our own). Leaf count assumed a power of two (BEP 52 zero-pads to that; padding is the trivial extension). No TLS. license_tier: ORIGINAL

dependencies 2 imports · 1 importers

nx_sha256.nx nx_syscalls.nx nx_bt_v2_merkle.nx nx_bt_v2_merkle_gate.nx

imports: nx_sha256.nxnx_syscalls.nx

imported by: nx_bt_v2_merkle_gate.nx

structs

none

consts

none

functions

10func mk_memeq(a: *u8, b: *u8, n: i64) -> i64 { var i: i64=0; while i<n { if a[i]!=b[i] { return 0 } i=i+1 } return 1 }
called by 2: mk_verifymain
12func mk_leaf(block: *u8, len: i64, out32: *u8) -> i64
17func mk_node(l: *u8, r: *u8, out32: *u8) -> i64
23func mk_root(leaves: *u8, n: i64, out32: *u8) -> i64
called by 1: main calls 2: sys_mmapmk_node
38func mk_proof(leaves: *u8, n: i64, idx: i64, proof: *u8) -> i64
called by 1: main calls 2: sys_mmapmk_node
51func mk_verify(leaf32: *u8, idx: i64, proof: *u8, np: i64, root32: *u8) -> i64
called by 1: main calls 3: sys_mmapmk_nodemk_memeq