code wiki / (root) / nx_esign_pure_gate.nx

nx_esign_pure_gate.nx source

↩ module page · 103 lines · 7155 B

1// nx_esign_pure_gate.nx -- INDEPENDENT GATE over the PURE DECISION CORE of nx_esign_lib. 2// ZERO registry writes, zero I/O: this gate proves the STATUTORY RULES, not the storage. That split is 3// deliberate -- when the seg_store write path stalled ecosystem-wide (debt 1785519597) the rules became 4// unverifiable purely because they sat behind a write. A correctness gate must not be hostage to a 5// storage outage, so the rules now gate independently and in microseconds. 6// 7// Because pure evaluation is free, the four-element test is proven EXHAUSTIVELY over all 16 8// combinations rather than on hand-picked cases: exactly one of the sixteen may be valid. An 9// exhaustive sweep cannot miss the case a hand-written list forgets. 10// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 11 12import "nx_esign_lib.nx" 13import "nx_gate_verdict.nx" 14 15func main(argc: i64, argv: *i64) -> i64 { 16 let ctr: *i64 = gv_ctr() 17 let lbl: *u8 = sys_mmap(32) 18 19 gv_head("NISHI-ESIGN-PURE-GATE (statutory rules, zero storage: exhaustive four-element sweep)" as *u8) 20 21 // ---- X: EXHAUSTIVE four-element sweep. Exactly ONE of sixteen may be enforceable. ---- 22 var valid_count: i64 = 0 23 var i: i64 = 0 24 while i < 16 { 25 let a: i64 = (i / 8) % 2 26 let b: i64 = (i / 4) % 2 27 let c: i64 = (i / 2) % 2 28 let d: i64 = i % 2 29 let v: i64 = es_ueta_pure(a, b, c, d) 30 let n: i64 = es_elements_pure(a, b, c, d) 31 valid_count = valid_count + v 32 // the element count must equal the number of asserted flags, for every combination 33 if n != (a + b + c + d) { ctr[1] = ctr[1] + 1 } 34 // validity must hold exactly when all four are asserted 35 if v == 1 { 36 if n != 4 { ctr[1] = ctr[1] + 1 } 37 } 38 i = i + 1 39 } 40 gv_check("X1 exactly ONE of 16 element combinations is enforceable" as *u8, valid_count == 1, ctr) 41 gv_check("X2 all four asserted -> valid" as *u8, es_ueta_pure(1, 1, 1, 1) == 1, ctr) 42 gv_check("X3 three of four (no intent) -> VOID" as *u8, es_ueta_pure(0, 1, 1, 1) == 0, ctr) 43 gv_check("X4 three of four (no retention) -> VOID" as *u8, es_ueta_pure(1, 1, 1, 0) == 0, ctr) 44 gv_check("X5 none asserted -> 0 elements" as *u8, es_elements_pure(0, 0, 0, 0) == 0, ctr) 45 gv_check("X6 garbage flag value is NOT an assertion (fail-closed)" as *u8, es_elements_pure(7, 2, 0 - 1, 99) == 0, ctr) 46 gv_check("X6a a garbage-flagged signature is not valid" as *u8, es_ueta_pure(7, 2, 0 - 1, 99) == 0, ctr) 47 48 // ---- C: the ESIGN 101(c) consumer overlay ---- 49 gv_check("C1 a NON-consumer passes the overlay vacuously" as *u8, es_consumer_pure(0, 0, 0, 0, 0) == 1, ctr) 50 gv_check("C2 a consumer with NO disclosures fails" as *u8, es_consumer_pure(1, 0, 0, 0, 0) == 0, ctr) 51 gv_check("C3 three of four disclosures still fails" as *u8, es_consumer_pure(1, 1, 1, 1, 0) == 0, ctr) 52 gv_check("C3a a different missing one also fails" as *u8, es_consumer_pure(1, 0, 1, 1, 1) == 0, ctr) 53 gv_check("C4 all four disclosures -> overlay satisfied" as *u8, es_consumer_pure(1, 1, 1, 1, 1) == 1, ctr) 54 55 // ---- A: eIDAS Art 26 -- every property is load-bearing ---- 56 gv_check("A1 all four advanced properties -> AES" as *u8, es_aes_pure(1, 1, 1, 1) == 1, ctr) 57 gv_check("A2 missing unique link -> not AES" as *u8, es_aes_pure(0, 1, 1, 1) == 0, ctr) 58 gv_check("A3 missing signatory id -> not AES" as *u8, es_aes_pure(1, 0, 1, 1) == 0, ctr) 59 gv_check("A4 missing SOLE CONTROL -> not AES" as *u8, es_aes_pure(1, 1, 0, 1) == 0, ctr) 60 gv_check("A5 missing tamper detection -> not AES" as *u8, es_aes_pure(1, 1, 1, 0) == 0, ctr) 61 62 // ---- T: the tier ladder ---- 63 gv_check("T1 nothing at all -> NONE (absence is not a tier)" as *u8, es_tier_pure(0, 0, 0, 0, 0, 0, 0) == ES_NONE, ctr) 64 gv_check("T2 signature data alone -> SES" as *u8, es_tier_pure(1, 0, 0, 0, 0, 0, 0) == ES_SES, ctr) 65 gv_check("T3 three advanced properties -> still SES" as *u8, es_tier_pure(1, 1, 1, 1, 0, 0, 0) == ES_SES, ctr) 66 gv_check("T4 all four advanced properties -> AES" as *u8, es_tier_pure(1, 1, 1, 1, 1, 0, 0) == ES_AES, ctr) 67 gv_check("T4a AES even without signature data flagged" as *u8, es_tier_pure(0, 1, 1, 1, 1, 0, 0) == ES_AES, ctr) 68 gv_check("T5 AES + QSCD but NO qualified cert -> still AES" as *u8, es_tier_pure(1, 1, 1, 1, 1, 1, 0) == ES_AES, ctr) 69 gv_check("T6 AES + qualified cert but NO QSCD -> still AES" as *u8, es_tier_pure(1, 1, 1, 1, 1, 0, 1) == ES_AES, ctr) 70 gv_check("T7 AES + BOTH -> QES" as *u8, es_tier_pure(1, 1, 1, 1, 1, 1, 1) == ES_QES, ctr) 71 gv_check("T8 QSCD and cert WITHOUT the Art 26 properties cannot reach QES" as *u8, es_tier_pure(1, 0, 0, 0, 0, 1, 1) == ES_SES, ctr) 72 73 // ---- E: THE SEPARATION. admissible reaches every tier; wet-ink equivalence is QES alone. ---- 74 gv_check("E1 NONE is not admissible" as *u8, es_admissible_pure(ES_NONE) == 0, ctr) 75 gv_check("E2 SES IS admissible (Art 25(1))" as *u8, es_admissible_pure(ES_SES) == 1, ctr) 76 gv_check("E3 AES is admissible" as *u8, es_admissible_pure(ES_AES) == 1, ctr) 77 gv_check("E4 QES is admissible" as *u8, es_admissible_pure(ES_QES) == 1, ctr) 78 gv_check("E5 NONE is not wet-ink equivalent" as *u8, es_handwritten_pure(ES_NONE) == 0, ctr) 79 gv_check("E6 SES is NOT wet-ink equivalent" as *u8, es_handwritten_pure(ES_SES) == 0, ctr) 80 gv_check("E7 AES is NOT wet-ink equivalent -- the costly conflation" as *u8, es_handwritten_pure(ES_AES) == 0, ctr) 81 gv_check("E8 QES ALONE is wet-ink equivalent (Art 25(2))" as *u8, es_handwritten_pure(ES_QES) == 1, ctr) 82 // the two predicates must genuinely differ somewhere, or the separation is cosmetic 83 gv_check("E9 admissible and wet-ink-equivalent DISAGREE at AES" as *u8, es_admissible_pure(ES_AES) == es_handwritten_pure(ES_AES) == 0, ctr) 84 gv_check("E9a and agree at QES" as *u8, es_admissible_pure(ES_QES) == es_handwritten_pure(ES_QES) == 1, ctr) 85 86 es_tier_label(ES_QES, lbl) 87 gv_check("E10 QES label" as *u8, mt_streq(lbl, "QES" as *u8) == 1, ctr) 88 es_tier_label(ES_NONE, lbl) 89 gv_check("E10a NONE label" as *u8, mt_streq(lbl, "NONE" as *u8) == 1, ctr) 90 91 // ---- U: the Certificate of Completion ---- 92 gv_check("U1 no audit facts -> six missing" as *u8, es_audit_missing_pure(0, 0, 0, 0, 0, 0) == 6, ctr) 93 gv_check("U2 all six -> none missing" as *u8, es_audit_missing_pure(1, 1, 1, 1, 1, 1) == 0, ctr) 94 gv_check("U3 one absent -> exactly one missing" as *u8, es_audit_missing_pure(1, 1, 1, 1, 1, 0) == 1, ctr) 95 96 // ---- R: readiness needs all three independently ---- 97 gv_check("R1 everything present -> READY" as *u8, es_ready_pure(1, ES_AES, 0) == 1, ctr) 98 gv_check("R2 US test failing blocks readiness" as *u8, es_ready_pure(0, ES_QES, 0) == 0, ctr) 99 gv_check("R3 no eIDAS tier blocks readiness" as *u8, es_ready_pure(1, ES_NONE, 0) == 0, ctr) 100 gv_check("R4 an incomplete audit record blocks readiness" as *u8, es_ready_pure(1, ES_QES, 1) == 0, ctr) 101 102 return gv_verdict("ESIGN-UETA-EIDAS" as *u8, ctr, "16/16 element sweep exhaustive; overlay independent; QES alone is wet-ink equivalent" as *u8) 103}