Weave documentation
Weave Crypto

Hashing and Merkle

Exact Blake2s256 Merkle framing and raw hashing.

Hashing contract

The current implementation uses Blake2s256, including hash, data, parent, tree, discovery keys and namespaces. Some older source comments call it Blake2b; the imported implementation and wire operations are authoritative.

FunctionBytes committed
hash(parts)Input buffers concatenated in order
data(bytes)Leaf tag 0, little-endian u64 byte length, then bytes
parent(left, right)Parent tag 1, combined size, then hashes ordered by node index
tree(roots)Root tag 2, then each supplied root's hash, index and size

data(bytes) is therefore not interchangeable with hash(&[bytes]). Generic hash adds no delimiters between buffers; add application framing when field boundaries matter.

use weave_crypto::{data, hash, hash_into};

let raw = hash(&[b"block-0"]);
let leaf = data(b"block-0");
assert_ne!(raw, leaf);
let mut output = [0u8; 32];
hash_into(&[b"block-0"], &mut output);
assert_eq!(output, raw);

Node carries index, size and hash; callers must provide the correct tree topology and root order.

Source reference

Exact declarations and source provenance · Package features and manifest.

On this page