code wiki / _hdl_build / nx_sh_safeharbor_gate.nx

nx_sh_safeharbor_gate.nx source

↩ module page · 53 lines · 3818 B

1// nx_sh_safeharbor_gate.nx -- proves the safe-harbor mechanism: an uploader ATTESTS (naming themselves the 2// responsible party) before content is carried; a DMCA-512 NOTICE tombstones a cid (idempotent); community FLAGS 3// auto-suppress abuse/malware; un-attested content is never carried. Responsibility shifts to peers; the hub honors 4// notices. ⚠NOT LEGAL ADVICE. expect_exit: 0 license_tier: ORIGINAL 5import "nx_sh_safeharbor.nx" 6import "nx_syscalls.nx" 7 8func g_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 9func g_streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8) { if a[i]!=b[i] { return 0 } i=i+1 } if b[i]!=(0 as u8) { return 0 } return 1 } 10func g_ck(name: *u8, cond: i64, st: *i64) -> i64 { st[1]=st[1]+1; if cond==1 { st[0]=st[0]+1; g_puts(" [OK] " as *u8) } else { g_puts(" [FAIL] " as *u8) } g_puts(name); g_puts("\n" as *u8); return 0 } 11 12func main() -> i64 { 13 g_puts("=== nx_sh_safeharbor_gate: shift responsibility to peers + honor takedowns ===\n" as *u8) 14 let st: *i64 = sys_mmap(64) as *i64; st[0]=0; st[1]=0 15 16 let abuf: *u8 = sys_mmap(65536); var alen: i64=0 17 let tbuf: *u8 = sys_mmap(65536); var tlen: i64=0 18 let fbuf: *u8 = sys_mmap(65536); var flen: i64=0 19 let cidA: *u8 = "cidAAA" as *u8; let cidB: *u8 = "cidBBB" as *u8; let cidC: *u8 = "cidCCC" as *u8 20 21 // uploader peerA attests cidA is legal + accepts responsibility 22 alen = sh_attest(abuf, alen, cidA, "peerA@lan" as *u8, 1, 1000) 23 let who: *u8 = sys_mmap(256); let found: i64 = sh_responsible(abuf, alen, cidA, who) 24 g_puts(" responsible party for cidA = "); g_puts(who); g_puts("\n" as *u8) 25 g_ck("T0 attestation names the uploader as the responsible party" as *u8, found & g_streq(who, "peerA@lan" as *u8), st) 26 g_ck("T1 cidA ACTIVE (attested, no takedown, no flags)" as *u8, sh_active(abuf,alen,tbuf,tlen,fbuf,flen,cidA,3)==1, st) 27 28 // a valid DMCA-512 notice comes in for cidA 29 tlen = sh_takedown(tbuf, tlen, cidA) 30 g_ck("T2 takedown tombstones cidA (notice honored)" as *u8, sh_is_taken_down(tbuf,tlen,cidA)==1, st) 31 g_ck("T3 cidA NO LONGER active after takedown (removed from index/serve)" as *u8, sh_active(abuf,alen,tbuf,tlen,fbuf,flen,cidA,3)==0, st) 32 let tlen2: i64 = sh_takedown(tbuf, tlen, cidA) 33 g_ck("T4 takedown is idempotent (additive, no dup)" as *u8, tlen2==tlen, st) 34 35 // cidB: attested, but the community flags it (malware/abuse) 3x 36 alen = sh_attest(abuf, alen, cidB, "peerB@wan" as *u8, 1, 1001) 37 flen = sh_flag(fbuf, flen, cidB, "flagger1" as *u8) 38 flen = sh_flag(fbuf, flen, cidB, "flagger2" as *u8) 39 flen = sh_flag(fbuf, flen, cidB, "flagger3" as *u8) 40 g_ck("T5 community flags auto-SUPPRESS cidB at threshold 3 (no hub curation)" as *u8, (sh_flag_count(fbuf,flen,cidB)==3) & (sh_active(abuf,alen,tbuf,tlen,fbuf,flen,cidB,3)==0), st) 41 42 // cidC: never attested -> the hub never carries it (no responsible party) 43 g_ck("T6 un-attested cidC is NOT carried (no one took responsibility)" as *u8, sh_active(abuf,alen,tbuf,tlen,fbuf,flen,cidC,3)==0, st) 44 45 g_ck("T7 SAFE-HARBOR: peer-responsibility + honored-takedown + community-flagging, all additive/sovereign" as *u8, 46 found & (sh_is_taken_down(tbuf,tlen,cidA)==1) & (sh_active(abuf,alen,tbuf,tlen,fbuf,flen,cidB,3)==0), st) 47 48 g_puts("\n PASS " as *u8); if st[0]==st[1] { g_puts("ALL" as *u8) } else { g_puts("PARTIAL" as *u8) } 49 let p: *u8=sys_mmap(8); p[0]=(48+st[0]) as u8; p[1]=47 as u8; p[2]=(48+st[1]) as u8; p[3]=0 as u8 50 g_puts(" ("); g_puts(p); g_puts(")\n" as *u8) 51 if st[0]==st[1] { g_puts("=== GREEN (safe-harbor: responsibility shifts to peers; notices honored; abuse suppressed) ===\n" as *u8); sys_exit(0); return 0 } 52 g_puts("=== RED ===\n" as *u8); sys_exit(1); return 1 53}