diff --git a/spatial/checker.py b/spatial/checker.py index ca82af3..be2a7c4 100644 --- a/spatial/checker.py +++ b/spatial/checker.py @@ -215,6 +215,30 @@ def evidence_for(full: FullState, query: Query) -> list: return [] +def _contact_is_real(ents: dict, e: Edge) -> bool: + """Re-derive a contact from the boxes instead of trusting the edge label. + + A certificate is only worth something if the thing it cites can be checked + independently. Until this existed, `validate_evidence` walked the claimed + chain and stopped as soon as it reached anything sitting on the ground -- so + a provider that emitted one bogus contact edge could forge support that + validated. Measured: with a distance tolerance of one grid unit (0.25mm) + every part pair separated by 0.25mm produced an edge that passed. + """ + a, b = ents.get(e.a), ents.get(e.b) + if a is None or b is None: + return False + ba, bb = _box(a), _box(b) + if ba and bb: + if not (ba[5] == bb[2] or bb[5] == ba[2]): + return False # faces do not meet: no load path + return _overlap(ba, bb) is not None # and they must share a footprint + box, other = (ba, b) if ba else (bb, a) + if box is None or other.kind != "ground": + return False + return box[2] == float(other.attrs.get("plane", 0)) + + def validate_evidence(full: FullState, query: Query, evidence) -> bool: """Independent re-check of a claimed certificate.""" evidence = list(evidence or []) @@ -235,6 +259,9 @@ def validate_evidence(full: FullState, query: Query, evidence) -> bool: ents = _index(full.entities) if query.a not in ents: return False + # every cited step has to be a contact that the geometry actually shows + if not all(_contact_is_real(ents, e) for e in edges): + return False reached = {query.a} for _ in range(len(edges) + 1): for e in edges: