HeadlinesBriefing favicon HeadlinesBriefing.com

bijou64 varint beats LEB128 with built‑in canonicality

Hacker News •
×

The Subduction CRDT team released bijou64, a variable‑length integer encoding designed to eliminate ambiguous representations in binary protocols. By guaranteeing a single canonical form for each value, the format prevents signature‑verification bugs that arise when different byte strings decode to the same number. The design emerged from a need to tighten security without sacrificing compactness.

Traditional varints such as LEB128 encode numbers in 7‑bit groups with a continuation flag, which allows multiple byte sequences for the same integer—zero can be written as 0x00, 0x80 0x00, or longer chains. Decoders typically accept any variant, forcing callers to add canonicality checks that increase complexity and open attack vectors in signed protocols, making it harder for attackers to exploit ambiguous encodings.

Bijou64 solves the problem by using the first byte as both value (0–247) and length tag (248–255), then offsetting subsequent bytes to ensure uniqueness. Benchmarks on Apple M2 Pro and AMD Zen 5 show median decode times of 3 µs for 4096 values, roughly 2–10× faster than LEB128, with no variance. The result is a fast, varint suitable for security‑critical sync layers. It simplifies code, dropping validation logic.