Build-time private LOS compiler

Compiler owner: crypto/algo/private-los/src/compiler.rs, build.rs and src/maps.rs. Root alone owns Cargo and compilation. This implementation is additive and changes no existing algorithm, SDK, workspace or benchmark matrix.

Geometry and widths

Position bits 0..3 are x and 4..7 are y. A position byte denotes the doubled centre A=(2ax+1,2ay+1), with coordinates ax,ay in 0..15. Public wall vertices (k,l) are doubled to (2k,2l), k,l in 0..16. Walls are closed, so endpoint contact blocks. Equal position bytes are visible because they never straddle a wall's supporting line.

The compiler shares dx=bx-ax and dy=by-ay (signed five bits, [-15,15]), two unsigned four-by-four products (eight bits, [0,225]), their zero-extended signed nine-bit difference D=axby-bxay ([-225,225]), and T=2D+dy-dx (signed ten bits, [-480,480]). Product zero extension before subtraction is required: values >=128 must remain positive.

Reduced orientation at a public vertex is O(k,l)=T+2dxl-2dyk. The ordinary doubled-coordinate determinant is exactly 2*O. O is affine in each of ax,ay,bx,by,k,l separately. Therefore its extrema on the complete coordinate box occur at its 64 corners. Those corners have exact minimum -480 and maximum 480. verify_geometry_widths checks the corner bounds before generation. This proves signed ten bits [-512,511] suffice for the final orientation for every position byte and allowed public vertex.

All endpoint additions, subtractions and multiplication by public constants are computed in the ring modulo 2^10. No sign or zero is tested on an intermediate. Although a conservative independent-term sum bound is +/-1440, ring arithmetic preserves the exact final residue; since the exact final value fits signed ten bits, its sign bit and equality to zero are exact. A separate build-only twelve-bit compilation retains that conservative bound. check_width_equivalence compares the ten/twelve-bit programs for all 65,536 position pairs for every shipped map, using 64 parallel Boolean lanes. Only the ten-bit program is emitted; there are no runtime variants.

For a vertical wall x=k, supporting-line straddle is (ax<k)!=(bx<k); for a horizontal wall y=l, use y instead. Odd centres can never lie on an even supporting line, so strict straddle is sufficient. Within-wall intersection is opposite endpoint orientation signs OR either endpoint orientation equal to zero. The conjunction is exactly closed segment intersection. Visibility is the negation of the balanced OR of all wall intersections.

Compiler and execution contract

The compiler folds constants and Boolean identities, normalizes XOR inversion edges, hash-conses common expressions, and removes every gate not reachable from the output. It uses one-AND full-adder carries, majority(a,b,c)=a XOR((a XOR b) AND(a XOR c)), plus cheaper constant carries. It shares dx/dy, determinant/T, public constant products, x-base expressions and repeated endpoint orientations across all walls.

Lit(u32) stores wire index shifted left one plus a complemented edge bit. Wire zero is false; NOT has no gate. Declared Alice inputs then Bob inputs keep their original index range, followed by generated gate output wires. Dead primary inputs have no active label/OT, and live input index arrays are sorted zero-based indices. Only a live constant wire requires its false active label; constant true is a complemented false output and reveals no free-XOR delta.

AND depth is one plus the maximum dependency AND depth; XOR depth is the maximum dependency depth. At each depth, all ANDs precede XORs, and XORs retain dependency order. Thus consecutive equal-depth ANDs are independent and can use the existing paired garbler/evaluator kernels. The generated Program contains only static immutable gates, counts, input liveness and public walls. Compiler HashMaps, public arithmetic and clear evaluators are build-only. Online private decisions are represented solely by this circuit. Build generation asserts the request payload is within the existing 1 MiB frame bound.

CompiledProgram::evaluate_clear is a pure build/test Boolean evaluator with caller-provided scratch; each u64 is 64 independent Boolean cases. It supports exhaustive width testing without a runtime plaintext API. The runtime owner supplies the separately fixture-gated Program::evaluate_plain for independent native geometry tests. The independent geometry reviewer owns tests/reference.rs, whose oracle uses i64 doubled points and general four orientation/on-segment tests rather than the compiler formula.

Maps

WALLS_0, WALLS_4, WALLS_16 and WALLS_64 contain exactly the first 0/4/16/64 rows below. Every wall has unit length and an interior supporting line, with no duplicate or overlapping segment. The source uses bit-reversed Morton coordinates to distribute small prefixes across the board: for row t, i=(t0<<2)|(t2<<1)|t4 and j=(t1<<2)|(t3<<1)|t5; start is (2i+1,2j+1). Even parity of all i,j bits makes it horizontal, odd parity vertical. This is public geometry, never a precomputed visibility mask.

Index Start End
0 (1,1) (2,1)
1 (9,1) (9,2)
2 (1,9) (1,10)
3 (9,9) (10,9)
4 (5,1) (5,2)
5 (13,1) (14,1)
6 (5,9) (6,9)
7 (13,9) (13,10)
8 (1,5) (1,6)
9 (9,5) (10,5)
10 (1,13) (2,13)
11 (9,13) (9,14)
12 (5,5) (6,5)
13 (13,5) (13,6)
14 (5,13) (5,14)
15 (13,13) (14,13)
16 (3,1) (3,2)
17 (11,1) (12,1)
18 (3,9) (4,9)
19 (11,9) (11,10)
20 (7,1) (8,1)
21 (15,1) (15,2)
22 (7,9) (7,10)
23 (15,9) (16,9)
24 (3,5) (4,5)
25 (11,5) (11,6)
26 (3,13) (3,14)
27 (11,13) (12,13)
28 (7,5) (7,6)
29 (15,5) (16,5)
30 (7,13) (8,13)
31 (15,13) (15,14)
32 (1,3) (1,4)
33 (9,3) (10,3)
34 (1,11) (2,11)
35 (9,11) (9,12)
36 (5,3) (6,3)
37 (13,3) (13,4)
38 (5,11) (5,12)
39 (13,11) (14,11)
40 (1,7) (2,7)
41 (9,7) (9,8)
42 (1,15) (1,16)
43 (9,15) (10,15)
44 (5,7) (5,8)
45 (13,7) (14,7)
46 (5,15) (6,15)
47 (13,15) (13,16)
48 (3,3) (4,3)
49 (11,3) (11,4)
50 (3,11) (3,12)
51 (11,11) (12,11)
52 (7,3) (7,4)
53 (15,3) (16,3)
54 (7,11) (8,11)
55 (15,11) (15,12)
56 (3,7) (3,8)
57 (11,7) (12,7)
58 (3,15) (4,15)
59 (11,15) (11,16)
60 (7,7) (8,7)
61 (15,7) (15,8)
62 (7,15) (7,16)
63 (15,15) (16,15)

Comparators and counts

EQUALITY_8 is a balanced eight-bit equality comparator (7 AND, 8 XOR, AND depth 3), with eight Alice and eight Bob inputs. Existing equality source is unchanged. SELECTOR_256 is an arbitrary synthetic 256:1 selector: 256 Alice bits, eight Bob selector bits, 255 AND, 510 XOR, AND depth 8. Its inputs are arbitrary Boolean patterns, never generated LOS masks. Its output chooses Alice bit indexed by Bob's byte. Label-selector preprocessing is outside this kernel and must be reported as unmeasured.

Generation writes OUT_DIR/program-stats.json with optimized AND/XOR/depth, wire and liveness counts for all six programs, and emits the same counts as Cargo diagnostics. Exact shipped LOS counts and root-owned build/test results will be recorded after the first compilation.