Skip to main content

Module chunked

Module chunked 

Source
Expand description

ChunkedPack manifest format and validation.

When a packfile exceeds DEFAULT_CHUNK_SIZE, the on-host helper splits it across multiple [ObjectBundle::ChunkedPack] contracts: one immutable pack-contract per chunk plus one immutable pack-contract for the manifest. The repo state’s ObjectBundle::ChunkedPack { manifest_hash, total_size, chunk_count } refers to the manifest, which in turn lists the chunks.

Anything in this module is “view-only” from the contract WASM’s perspective — the contract just sees opaque bytes whose BLAKE3 hash must equal the manifest hash that the repo state declares. All the schema and validation logic here runs in the on-host helper.

§Wire format (v1)

manifest = bincode<{
  version:      u8 = 1,
  chunk_size:   u32,        // bytes per non-final chunk
  total_size:   u64,        // sum of all chunk lengths
  chunk_count:  u32,        // == chunk_hashes.len()
  chunk_hashes: Vec<[u8; 32]>,  // BLAKE3-32 of each chunk's bytes, in order
}>

bincode with default config is deterministic for this shape (only fixed-size primitives and a length-prefixed Vec of fixed-size byte arrays). A worked-example test pins the bytes; any change is a wire-format break.

§Validation rules (enforced at decode time)

ChunkedPackManifestV1::validate rejects manifests where any of:

  • version != 1
  • chunk_count == 0
  • chunk_count != chunk_hashes.len()
  • chunk_size == 0
  • total_size == 0
  • total_size > chunk_size as u64 * chunk_count as u64 — would imply the final chunk is larger than chunk_size.
  • total_size <= chunk_size as u64 * (chunk_count - 1) as u64 — would imply the final chunk is empty.

Per-chunk byte length verification (each non-final chunk equals chunk_size, final equals total_size - (chunk_count-1)*chunk_size) is enforced when the helper actually fetches and concatenates the chunks.

Structs§

ChunkedPackManifestV1
On-the-wire manifest for a chunked pack.

Enums§

ManifestError
Errors when validating or decoding a manifest.

Constants§

DEFAULT_CHUNK_SIZE
Default chunk size used by the on-host helper when splitting large packs. 1 MiB = 1,048,576 bytes. A pack of exactly 1 MiB is SinglePack; 1 MiB + 1 byte is ChunkedPack with two chunks.

Functions§

split_pack
Split a packfile’s bytes into chunks of chunk_size (final chunk may be smaller). Always produces at least one chunk; pack must not be empty.