code wiki / (root) / nx_esign_gate.nx

nx_esign_gate.nx source

↩ module page · 115 lines · 5341 B

1// nx_esign_gate.nx -- INDEPENDENT GATE: the ESIGN/UETA four-element test (core teeth). 2// Proves the two things that decide enforceability: (1) the test is ALL-OR-NOTHING -- three of four is 3// VOID, and the fourth element is what flips it; (2) the ESIGN 101(c) CONSUMER OVERLAY is independent -- 4// a consumer signature with a PERFECT 4/4 base test is still unenforceable without the disclosures. 5// 6// WRITE BUDGET (debt 1785519597): reg_put is disk-bound at ~0.7s+ and degrades under NAS I/O contention, 7// while reg_get is ~70us. This gate therefore upgrades ONE signature and spends exactly FIVE writes, 8// with unlimited free assertions between them. Wider coverage lives in sibling gates 9// (nx_esign_eidas_gate) rather than being crammed here past the execution budget. 10// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 11 12import "nx_esign_lib.nx" 13 14func zz_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 15func zz_putn(v: i64) -> i64 { 16 let t: *u8 = sys_mmap(32) 17 var o: i64 = 0 18 var m: i64 = v 19 if m < 0 { t[o] = 45 as u8; o = o + 1; m = 0 - m } 20 let d: *u8 = sys_mmap(32) 21 var k: i64 = 0 22 if m == 0 { d[0] = 48 as u8; k = 1 } 23 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 24 var i: i64 = 0 25 while i < k { t[o] = d[k - 1 - i]; o = o + 1; i = i + 1 } 26 sys_write(1, t, o) 27 return 0 28} 29func zz_ck(cnt: *i64, name: *u8, got: i64, want: i64) -> i64 { 30 if got == want { 31 cnt[0] = cnt[0] + 1 32 zz_puts(" PASS " as *u8); zz_puts(name); zz_puts(" = " as *u8); zz_putn(got); zz_puts("\n" as *u8) 33 return 1 34 } 35 cnt[1] = cnt[1] + 1 36 zz_puts(" FAIL " as *u8); zz_puts(name); zz_puts(" got " as *u8); zz_putn(got) 37 zz_puts(" want " as *u8); zz_putn(want); zz_puts("\n" as *u8) 38 return 0 39} 40func zz_cks(cnt: *i64, name: *u8, got: *u8, want: *u8) -> i64 { 41 if mt_streq(got, want) == 1 { 42 cnt[0] = cnt[0] + 1 43 zz_puts(" PASS " as *u8); zz_puts(name); zz_puts(" = " as *u8); zz_puts(got); zz_puts("\n" as *u8) 44 return 1 45 } 46 cnt[1] = cnt[1] + 1 47 zz_puts(" FAIL " as *u8); zz_puts(name); zz_puts(" got " as *u8); zz_puts(got) 48 zz_puts(" want " as *u8); zz_puts(want); zz_puts("\n" as *u8) 49 return 0 50} 51func zz_pfx(tag: *u8, nonce: i64, out: *u8) -> i64 { 52 var o: i64 = mt_catcopy(out, 0, "knowledge/store/" as *u8) 53 o = mt_catcopy(out, o, tag) 54 o = mt_catn(out, o, nonce) 55 out[o] = 45 as u8 56 o = o + 1 57 out[o] = 0 as u8 58 return o 59} 60 61 62func main(argc: i64, argv: *i64) -> i64 { 63 let nonce: i64 = sys_now_us() 64 let cnt: *i64 = sys_mmap(16) as *i64 65 cnt[0] = 0 66 cnt[1] = 0 67 let sig: *u8 = "S" as *u8 68 let p: *u8 = sys_mmap(256) 69 let e: *u8 = sys_mmap(256) 70 zz_pfx("esgA" as *u8, nonce, p) 71 zz_pfx("esgB" as *u8, nonce, e) 72 73 zz_puts("NISHI-ESIGN-GATE (ESIGN/UETA four-element test + 101(c) consumer overlay, fail-closed) 74" as *u8) 75 76 zz_ck(cnt, "Z1 unrecorded signature -> 0 elements" as *u8, es_elements(e, sig), 0) 77 zz_ck(cnt, "Z1a never valid by omission" as *u8, es_ueta_valid(e, sig), 0) 78 zz_ck(cnt, "Z1b never ready to rely on" as *u8, es_ready(e, sig), 0) 79 zz_ck(cnt, "Z1c an absent element is not asserted" as *u8, es_intent(e, sig), 0) 80 81 es_set(p, sig, "intent" as *u8, "yes" as *u8) 82 zz_ck(cnt, "B1 intent alone -> 1 element" as *u8, es_elements(p, sig), 1) 83 zz_ck(cnt, "B1a one of four is not valid" as *u8, es_ueta_valid(p, sig), 0) 84 es_set(p, sig, "consent" as *u8, "yes" as *u8) 85 zz_ck(cnt, "B2 + consent -> 2 elements" as *u8, es_elements(p, sig), 2) 86 zz_ck(cnt, "B2a two of four is not valid" as *u8, es_ueta_valid(p, sig), 0) 87 es_set(p, sig, "association" as *u8, "yes" as *u8) 88 zz_ck(cnt, "B3 + association -> 3 elements" as *u8, es_elements(p, sig), 3) 89 zz_ck(cnt, "B3a THREE of four is VOID, not mostly-valid" as *u8, es_ueta_valid(p, sig), 0) 90 es_set(p, sig, "retention" as *u8, "yes" as *u8) 91 zz_ck(cnt, "B4 + retention -> 4 elements" as *u8, es_elements(p, sig), 4) 92 zz_ck(cnt, "B4a the FOURTH element flips it VALID" as *u8, es_ueta_valid(p, sig), 1) 93 zz_ck(cnt, "B4b each element is independently readable" as *u8, es_retention(p, sig), 1) 94 zz_ck(cnt, "B4c a business signer carries no overlay" as *u8, es_consumer_ok(p, sig), 1) 95 zz_ck(cnt, "B4d -> enforceable under ESIGN" as *u8, es_esign_valid(p, sig), 1) 96 zz_ck(cnt, "B4e but with no eIDAS tier it is still not ready" as *u8, es_ready(p, sig), 0) 97 98 es_set(p, sig, "signer_type" as *u8, "consumer" as *u8) 99 zz_ck(cnt, "C1 SAME signature as a consumer: base test still 4/4" as *u8, es_ueta_valid(p, sig), 1) 100 zz_ck(cnt, "C1a but the 101(c) overlay FAILS" as *u8, es_consumer_ok(p, sig), 0) 101 zz_ck(cnt, "C1b enforceability DROPS to 0 on identical elements" as *u8, es_esign_valid(p, sig), 0) 102 zz_ck(cnt, "C1c -> and it is not ready to rely on" as *u8, es_ready(p, sig), 0) 103 104 zz_puts("nx_esign_gate: pass=" as *u8); zz_putn(cnt[0]) 105 zz_puts(" fail=" as *u8); zz_putn(cnt[1]); zz_puts(" 106" as *u8) 107 if cnt[1] == 0 { 108 zz_puts("ESIGN nx_esign: VERDICT=GREEN (four-element test all-or-nothing; consumer overlay independently enforced) 109" as *u8) 110 return 0 111 } 112 zz_puts("ESIGN nx_esign: VERDICT=RED 113" as *u8) 114 return 1 115}