nx_meshvalid_gate.nx source
↩ module page · 154 lines · 9964 B
1// nx_meshvalid_gate.nx -- the gate for nx_meshvalid_lib (/compare/dcc DC3).
2//
3// THE HAZARD THIS GATE IS SHAPED AGAINST: a validity checker that REFUSES EVERYTHING passes every negative
4// test ever written for it. That is the inverse of the usual vacuity defect -- there the guard never fires,
5// here it always does -- and four SSRF deny-tests once went green in this estate while the guard was wholly
6// broken. So the load-bearing cell here is the POSITIVE control: a genuine closed tetrahedron with
7// consistent outward winding that must come back with EVERY counter at zero. Each defect class is then a
8// gv_bite: it must FIRE on its own planted defect and stay SILENT on the good mesh.
9//
10// The tetrahedron is built once and mutated per fixture, so every negative control differs from the positive
11// one by exactly the defect under test -- if it differed by more, a kill would not attribute to the defect.
12// 100% sovereign. No hardware writes (Rule 26). license_tier: ORIGINAL expect_exit: 0
13import "nx_syscalls.nx"
14import "nx_gate_verdict.nx"
15import "nx_meshvalid_lib.nx"
16
17const MG_S: i64 = 100
18const MG_TETRA_V: i64 = 4
19const MG_TETRA_T: i64 = 4
20const MG_TRI_T: i64 = 1 // one triangle in the single-face fixtures
21
22// TWO CLASSES OF LITERAL LIVE IN THIS GATE AND ONLY ONE OF THEM IS A DEFECT. The vertex/face index triples
23// inside mg_tetra and the two single-triangle fixtures ARE the fixture's data -- (0,2,1) is the definition
24// of that face, not a second copy of anything, and naming its components would make the hand-verified
25// outward winding unreadable. What WAS a defect is every place a quantity already declared elsewhere got
26// written out again here: the index of the first EXTRA element (MG_TETRA_V / MG_TETRA_T), the edge count of
27// a triangle (MV_TVERT, from the lib), and the load factor (MV_LOAD_NUM, from the lib). Those are now read
28// from their one declaration, so the lib cannot change under this gate while its teeth keep passing.
29
30// Two element counts far enough apart that the derived capacity must differ. The tooth asserts only the
31// ordering, so nothing depends on these particular values.
32const MG_CAP_SMALL: i64 = 10
33const MG_CAP_BIG: i64 = 1000
34// A power of two, so the derived capacity must round strictly PAST n * MV_LOAD_NUM rather than landing on
35// it. The load factor itself is read from the lib below: writing a 4 here again would let the lib's
36// declared factor change while this tooth carried on passing against the old one.
37const MG_CAP_PROBE: i64 = 64
38
39func mg_eq(a: i64, b: i64) -> i64 { if a == b { return 1 } return 0 }
40func mg_ne(a: i64, b: i64) -> i64 { if a != b { return 1 } return 0 }
41func mg_gt(a: i64, b: i64) -> i64 { if a > b { return 1 } return 0 }
42
43// A closed tetrahedron with every face wound outward. Verified by hand: the cross product of each face
44// points away from the centroid, and therefore every shared edge is traversed once in each direction, which
45// is what makes the winding balance zero and the surface orientable.
46func mg_tetra(extra_v: i64, extra_t: i64) -> *i64 {
47 let m: *i64 = mv_new(MG_TETRA_V + extra_v, MG_TETRA_T + extra_t)
48 if (m as i64) == 0 { return m }
49 mv_set_vert(m, 0, 0, 0, 0)
50 mv_set_vert(m, 1, MG_S, 0, 0)
51 mv_set_vert(m, 2, 0, MG_S, 0)
52 mv_set_vert(m, 3, 0, 0, MG_S)
53 mv_set_tri(m, 0, 0, 2, 1)
54 mv_set_tri(m, 1, 0, 1, 3)
55 mv_set_tri(m, 2, 0, 3, 2)
56 mv_set_tri(m, 3, 1, 2, 3)
57 return m
58}
59
60func mg_all_clean(m: *i64) -> i64 {
61 var ok: i64 = 1
62 var s: i64 = MV_C_DEGEN
63 while s <= MV_C_DUPV { if mv_count(m, s) != 0 { ok = 0 } s = s + 1 }
64 return ok
65}
66
67func main(argc: i64, argv: *i64) -> i64 {
68 let ctr: *i64 = gv_ctr()
69 gv_head("nx_meshvalid_gate -- the mesh validity referee: named classes, first offenders, and a refusal" as *u8)
70
71 // ---- THE POSITIVE CONTROL. If this is not clean, nothing below means anything. ----
72 let good: *i64 = mg_tetra(0, 0)
73 gv_check("fixture-allocated" as *u8, mg_ne(good as i64, 0), ctr)
74 gv_check("abstains-before-the-check-is-run" as *u8, mg_eq(mv_manifold(good), 0 - 1), ctr)
75 gv_check("verdict-before-run-is-not-run" as *u8, mg_eq(mv_verdict(good), MV_E_NOTRUN), ctr)
76 let grc: i64 = mv_check(good)
77 gv_check("closed-tetrahedron-is-VALID" as *u8, mg_eq(grc, MV_OK), ctr)
78 gv_check("closed-tetrahedron-reads-manifold" as *u8, mg_eq(mv_manifold(good), 1), ctr)
79 gv_check("positive-control-has-every-counter-at-zero" as *u8, mg_all_clean(good), ctr)
80 gv_check("a-clean-class-reports-no-first-offender" as *u8, mg_eq(mv_first(good, MV_C_BOUND), 0 - 1), ctr)
81
82 // ---- NEGATIVE CONTROLS: one planted defect each, every other fixture property held identical ----
83
84 // BOUNDARY: a single open triangle has three edges used once each.
85 let hole: *i64 = mv_new(MV_TVERT, MG_TRI_T)
86 mv_set_vert(hole, 0, 0, 0, 0)
87 mv_set_vert(hole, 1, MG_S, 0, 0)
88 mv_set_vert(hole, 2, 0, MG_S, 0)
89 mv_set_tri(hole, 0, 0, 1, 2)
90 let hrc: i64 = mv_check(hole)
91 gv_bite("neg-control-boundary-edge-hole" as *u8, mg_gt(mv_count(hole, MV_C_BOUND), 0), mg_gt(mv_count(good, MV_C_BOUND), 0), ctr)
92 gv_check("an-open-triangle-has-exactly-three-boundary-edges" as *u8, mg_eq(mv_count(hole, MV_C_BOUND), MV_TVERT), ctr)
93 gv_check("boundary-refusal-is-named" as *u8, mg_eq(hrc, MV_E_BOUND), ctr)
94 gv_check("an-open-surface-is-not-manifold" as *u8, mg_eq(mv_manifold(hole), 0), ctr)
95
96 // DEGENERATE: three collinear points. Exact cross product, so this is degenerate rather than nearly so.
97 let deg: *i64 = mv_new(MV_TVERT, MG_TRI_T)
98 mv_set_vert(deg, 0, 0, 0, 0)
99 mv_set_vert(deg, 1, MG_S, 0, 0)
100 mv_set_vert(deg, 2, MG_S + MG_S, 0, 0)
101 mv_set_tri(deg, 0, 0, 1, 2)
102 let drc: i64 = mv_check(deg)
103 gv_bite("neg-control-degenerate-triangle" as *u8, mg_eq(mv_count(deg, MV_C_DEGEN), 1), mg_gt(mv_count(good, MV_C_DEGEN), 0), ctr)
104 gv_check("degeneracy-outranks-the-topology-classes" as *u8, mg_eq(drc, MV_E_DEGEN), ctr)
105 gv_check("degenerate-first-offender-names-the-triangle" as *u8, mg_eq(mv_first(deg, MV_C_DEGEN), 0), ctr)
106
107 // NON-MANIFOLD: a fifth vertex and a fifth triangle re-using the edge (0,1), so that edge has three uses.
108 let nm: *i64 = mg_tetra(1, 1)
109 mv_set_vert(nm, MG_TETRA_V, 0, 0, 0 - MG_S)
110 mv_set_tri(nm, MG_TETRA_T, 0, 1, MG_TETRA_V)
111 let nrc: i64 = mv_check(nm)
112 gv_bite("neg-control-non-manifold-edge" as *u8, mg_gt(mv_count(nm, MV_C_NONMAN), 0), mg_gt(mv_count(good, MV_C_NONMAN), 0), ctr)
113 gv_check("non-manifold-refusal-outranks-the-hole-it-also-creates" as *u8, mg_eq(nrc, MV_E_NONMAN), ctr)
114 gv_check("the-fin-also-honestly-reports-its-boundary-edges" as *u8, mg_gt(mv_count(nm, MV_C_BOUND), 0), ctr)
115
116 // WINDING: the tetrahedron with ONE face reversed. Closed and manifold still, but not orientable.
117 let wnd: *i64 = mg_tetra(0, 0)
118 mv_set_tri(wnd, MG_TETRA_T - 1, 1, 3, 2)
119 let wrc: i64 = mv_check(wnd)
120 gv_bite("neg-control-inconsistent-winding" as *u8, mg_gt(mv_count(wnd, MV_C_WIND), 0), mg_gt(mv_count(good, MV_C_WIND), 0), ctr)
121 gv_check("winding-refusal-is-named" as *u8, mg_eq(wrc, MV_E_WIND), ctr)
122 gv_check("a-reversed-face-leaves-the-surface-closed" as *u8, mg_eq(mv_count(wnd, MV_C_BOUND), 0), ctr)
123 gv_check("a-reversed-face-leaves-the-surface-manifold" as *u8, mg_eq(mv_count(wnd, MV_C_NONMAN), 0), ctr)
124
125 // DUPLICATE VERTEX: a fifth vertex at exactly v0's coordinates, geometry otherwise untouched.
126 let dup: *i64 = mg_tetra(1, 0)
127 mv_set_vert(dup, MG_TETRA_V, 0, 0, 0)
128 let urc: i64 = mv_check(dup)
129 gv_bite("neg-control-duplicate-vertex" as *u8, mg_eq(mv_count(dup, MV_C_DUPV), 1), mg_gt(mv_count(good, MV_C_DUPV), 0), ctr)
130 gv_check("duplicate-vertex-refusal-is-named" as *u8, mg_eq(urc, MV_E_DUPV), ctr)
131 gv_check("duplicate-first-offender-names-the-vertex" as *u8, mg_eq(mv_first(dup, MV_C_DUPV), MG_TETRA_V), ctr)
132
133 // INDEX RANGE: it must run FIRST and ALONE, because every later class dereferences these indices.
134 let bad: *i64 = mg_tetra(0, 1)
135 mv_set_tri(bad, MG_TETRA_T, 0, 1, MG_TETRA_V)
136 let brc: i64 = mv_check(bad)
137 gv_bite("neg-control-triangle-index-out-of-range" as *u8, mg_gt(mv_count(bad, MV_C_INDEX), 0), mg_gt(mv_count(good, MV_C_INDEX), 0), ctr)
138 gv_check("index-refusal-is-named" as *u8, mg_eq(brc, MV_E_INDEX), ctr)
139 gv_check("index-check-short-circuits-before-dereferencing" as *u8, mg_eq(mv_count(bad, MV_C_DEGEN), 0), ctr)
140
141 // ---- the instrument itself ----
142 gv_check("every-refusal-class-carries-a-distinct-name" as *u8, mg_ne(mv_err_name(MV_E_BOUND) as i64, mv_err_name(MV_E_NONMAN) as i64), ctr)
143 gv_check("table-capacity-is-derived-from-the-input-not-fixed" as *u8, mg_gt(mv_cap_for(MG_CAP_BIG), mv_cap_for(MG_CAP_SMALL)), ctr)
144 gv_check("capacity-holds-the-declared-quarter-load-factor" as *u8, mg_eq(mg_gt(mv_cap_for(MG_CAP_PROBE), MG_CAP_PROBE * MV_LOAD_NUM - 1), 1), ctr)
145 gv_check("a-bad-counter-slot-refuses-rather-than-reading-out-of-range" as *u8, mg_eq(mv_count(good, 0), 0 - 1), ctr)
146 // THE STRUCTURAL INVARIANT BEHIND A REAL BUG THIS GATE CAUGHT. The header must end above the highest
147 // first-offender slot or those slots alias the vertex array, and the ONLY symptom was a vacuous
148 // duplicate-vertex detector -- every other class still passed because a moved corner is still a valid
149 // tetrahedron. The duplicate-vertex negative control above is the behavioural form of this same check;
150 // this one states it arithmetically so a future slot addition cannot reintroduce the aliasing quietly.
151 gv_check("header-outranks-every-first-offender-slot" as *u8, mg_gt(MV_HDR, MV_C_DUPV + MV_FIRST_STRIDE), ctr)
152
153 return gv_verdict("nx_meshvalid_gate" as *u8, ctr, "the rivals show mesh defects in an overlay for a person to notice; this one names the class, names the offending element and refuses, which is what an asset pipeline with nobody watching actually needs" as *u8)
154}