Skip to content

feat(net): name the req/resp allocation bounds and prove the wire-size theorem - #75

Merged
adust09 merged 1 commit into
mainfrom
feat/net-allocation-bounds
Jul 30, 2026
Merged

feat(net): name the req/resp allocation bounds and prove the wire-size theorem#75
adust09 merged 1 commit into
mainfrom
feat/net-allocation-bounds

Conversation

@adust09

@adust09 adust09 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Delivers #70 (promote proven req/resp payload bounds to normative allocation constants).

New file LeanSpec/Networking/Allocation.lean, building on NET-1/NET-2 (payload_size_bound, compressed_size_bound):

  • varintSize — LEB128 byte count, mirroring upstream varint.py's encode_varint 7-bit-group loop, with varintSize_le_of_lt_pow.
  • MAX_COMPRESSED_PAYLOAD_SIZE = 12 234 410 bytes (rfl-proved closed form): snappy's worst-case expansion (n + n/6 + 1024) of a maximal in-bound payload.
  • MAX_LENGTH_PREFIX_SIZE = 4 bytes: any declared length the reader can accept encodes in ≤ 4 varint bytes (128^4 > MAX_PAYLOAD_SIZE).
  • MAX_REQUEST_WIRE_SIZE = 12 234 414 bytes, with the headline theorem request_wire_bound: for any request the reader accepts, varint prefix + compressed payload fit in the constant — for every decompressor (snappy enters the model as a parameter).

This is the machine-checked basis for the upstream proposal (spec-feedback.md format): "clients MAY preallocate 12 234 414 bytes per req/resp stream; a conforming reader never buffers more". Under-allocation is impossible by theorem; over-allocation is waste the constant eliminates.

All theorems sorry-free; lake build passes.

Closes #70

…e theorem

Deliver #70: closed-form allocation constants derived from the proven
NET-1/NET-2 acceptance bounds, as the basis for an upstream normative
preallocation proposal.

- varintSize models encode_varint's LEB128 byte count (varint.py);
  varintSize_le_of_lt_pow bounds it by the 7-bit group count.
- MAX_COMPRESSED_PAYLOAD_SIZE (12,234,410 B): snappy worst-case
  expansion of a maximal in-bound payload, matching the reader gate.
- MAX_LENGTH_PREFIX_SIZE (4 B): any accepted declared length encodes
  in at most 4 varint bytes (128^4 > MAX_PAYLOAD_SIZE).
- MAX_REQUEST_WIRE_SIZE (12,234,414 B) with request_wire_bound: for
  any accepted request, length prefix plus compressed payload fit in
  the constant — for every decompressor, so a conforming client may
  preallocate exactly this much per req/resp stream and
  under-allocation is impossible by theorem.
@adust09
adust09 merged commit a06da95 into main Jul 30, 2026
1 check passed
@adust09
adust09 deleted the feat/net-allocation-bounds branch July 30, 2026 04:12
adust09 added a commit that referenced this pull request Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Promote proven req/resp payload bounds (NET-1/NET-2) to normative allocation constants upstream

1 participant