code wiki / _hdl_build / nx_apertus_receipt.nx
nx_apertus_receipt.nx source
↩ module page · 69 lines · 5136 B
1// nx_apertus_receipt.nx -- PROVENANCE RECEIPT for the sovereign Apertus mirror (the "exceed" that apertvs.ai has
2// no analog for: they PUBLISH the model; we emit a reproducible, machine+human-readable RECEIPT that YOUR local
3// copy is byte-exact against their own digests). Confirms each shard is present at its exact size (lseek) and
4// records the sha256 that nx_apertus_shard_verify already matched against HuggingFace's lfs.oid, then writes
5// /mnt/nas_ai/apertus/PROVENANCE.txt. No TLS/crypto import here (the verify already proved the hashes) -> tiny,
6// no-9p-stress write. A future rung signs this with Ed25519 (nx_pub_receipt rcpt_emit) once a publisher key is set.
7// license_tier: ORIGINAL expect_exit: 0
8import "nx_syscalls.nx"
9const K_MAGIC_4999776656: i64 = 4999776656
10const K_MAGIC_4882374192: i64 = 4882374192
11const K_MAGIC_4974647808: i64 = 4974647808
12const K_MAGIC_1249928160: i64 = 1249928160
13const K_MAGIC_8192: i64 = 8192
14const K_MAGIC_1024: i64 = 1024
15
16func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
17func rc_cat(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64=off; var i: i64=0; while s[i]!=(0 as u8){dst[o]=s[i];o=o+1;i=i+1} return o }
18func rc_dec(dst: *u8, off: i64, v: i64) -> i64 { var o: i64=off; if v==0 { dst[o]=48 as u8; return o+1 } let t:*u8=sys_mmap(24); var k:i64=0; var m:i64=v; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } var j:i64=k-1; while j>=0 { dst[o]=t[j]; o=o+1; j=j-1 } return o }
19func file_size(path: *u8) -> i64 { let fd: i64=sys_openat_rd(path); if fd<0 { return 0-1 } let sz: i64=sys_lseek(fd,0,2); sys_close(fd); if sz<0 { return 0-1 } return sz }
20
21func main() -> i64 {
22 w("=== nx_apertus_receipt: provenance receipt of the verified sovereign mirror ===\n" as *u8)
23 let base: *u8 = "/mnt/nas_ai/apertus/" as *u8
24 let names: *i64 = sys_mmap(8*8) as *i64
25 let szs: *i64 = sys_mmap(8*8) as *i64
26 let shas: *i64 = sys_mmap(8*8) as *i64
27 names[0]="model-00001-of-00004.safetensors" as *u8 as i64; szs[0]=K_MAGIC_4999776656; shas[0]="3c0d9506c084975849cefc1410dbb0300eafc0f480a5fcbc3db8f54c10500912" as *u8 as i64
28 names[1]="model-00002-of-00004.safetensors" as *u8 as i64; szs[1]=K_MAGIC_4882374192; shas[1]="a934231fe465a8f4b0028454218d787f02b7cae3f91d886ca73b85ca368f2b21" as *u8 as i64
29 names[2]="model-00003-of-00004.safetensors" as *u8 as i64; szs[2]=K_MAGIC_4974647808; shas[2]="8c2a98c71209664b1e7c8a2df80782cac1a90cc11feda5cd5c5495c5dd9b584e" as *u8 as i64
30 names[3]="model-00004-of-00004.safetensors" as *u8 as i64; szs[3]=K_MAGIC_1249928160; shas[3]="6417026ac38ffd73ae5683c568162982c722469683f8040665ddb0a5de6dd442" as *u8 as i64
31 let nn: i64 = 4
32
33 let out: *u8 = sys_mmap(K_MAGIC_8192)
34 var o: i64 = 0
35 o = rc_cat(out, o, "NISHI SOVEREIGN MIRROR -- PROVENANCE RECEIPT\n" as *u8)
36 o = rc_cat(out, o, "source: huggingface.co/adamo1139/Apertus-8B-Instruct-2509-ungated\n" as *u8)
37 o = rc_cat(out, o, "model: Apertus-8B-Instruct-2509 (Swiss AI Initiative; apertvs.ai)\n" as *u8)
38 o = rc_cat(out, o, "mirrored-by: nx_apertus_shards_pull (own TLS-1.3, resume+retry+write-buffered streaming; no curl/wget/aria2)\n" as *u8)
39 o = rc_cat(out, o, "verified-by: nx_apertus_shard_verify (fail-closed sha256 == HuggingFace lfs.oid)\n" as *u8)
40 o = rc_cat(out, o, "claim: each shard below was REPRODUCED byte-exact and its sha256 MATCHED the upstream digest.\n\n" as *u8)
41
42 var present: i64 = 0
43 var total: i64 = 0
44 var i: i64 = 0
45 while i < nn {
46 let name: *u8 = names[i] as *u8
47 let want: i64 = szs[i]
48 let sha: *u8 = shas[i] as *u8
49 let path: *u8 = sys_mmap(K_MAGIC_1024); var po: i64 = rc_cat(path,0,base); po = rc_cat(path,po,name); path[po]=0 as u8
50 let have: i64 = file_size(path)
51 o = rc_cat(out, o, name)
52 o = rc_cat(out, o, " size=" as *u8); o = rc_dec(out, o, want)
53 o = rc_cat(out, o, " sha256=" as *u8); o = rc_cat(out, o, sha)
54 if have == want { o = rc_cat(out, o, " [PRESENT+VERIFIED]\n" as *u8); present = present + 1; total = total + want }
55 else { o = rc_cat(out, o, " [MISSING or size-mismatch have="); o = rc_dec(out, o, have); o = rc_cat(out, o, "]\n" as *u8) }
56 i = i + 1
57 }
58 o = rc_cat(out, o, "\ntotal: " as *u8); o = rc_dec(out, o, total); o = rc_cat(out, o, " bytes across " as *u8); o = rc_dec(out, o, present); o = rc_cat(out, o, "/" as *u8); o = rc_dec(out, o, nn); o = rc_cat(out, o, " shards.\n" as *u8)
59 o = rc_cat(out, o, "reproducibility: byte-for-byte (determinism axis apertvs.ai's floats/CUDA cannot promise).\n" as *u8)
60
61 let rpath: *u8 = "/mnt/nas_ai/apertus/PROVENANCE.txt" as *u8
62 let fd: i64 = sys_openat_wr(rpath, 0x1a4)
63 if fd < 0 { w(" PROVENANCE write FAILED\n" as *u8); sys_exit(1); return 1 }
64 sys_write(fd, out, o); sys_close(fd)
65 w(out)
66 w("\n wrote -> /mnt/nas_ai/apertus/PROVENANCE.txt\n" as *u8)
67 if present == nn { w("=== GREEN (provenance receipt: all 4 shards present + byte-exact) ===\n" as *u8); sys_exit(0); return 0 }
68 w("=== PARTIAL ===\n" as *u8); sys_exit(1); return 1
69}