interplane.Get Omega
Read in your language

omnet

aien-dev/omnet

Brought by drakestapleton

branch main Branches Tags History

omnet / om / tka / README.md

129 lines · 9838 bytes Raw Blame History Rendered
1# Bounded Tailnet Key Authority
2
3Omega implementation of the typed AUM, Key, State and AUM Signature models, signature authorization,
4state transitions, and an in-memory authority DAG. Behavior is pinned to
5[Tailscale v1.102.0](https://github.com/tailscale/tailscale/tree/v1.102.0/tka), particularly `aum.go`,
6`key.go`, `state.go`, `tka.go`, and `sync.go`. No production Go code or node-key-signature implementation
7is included here. Node-key signatures belong to `om/tkasig`.
8
9## Composition
10
11Concatenate `om/blake2s/blake2s.om`, `om/sha512/sha512.om`, `om/ed25519/ed25519.om`,
12`om/cbor/cbor.om`, `tka.om`, `tkastate.om`, and, for the authority API, `tkapool.om`, before the caller.
13The first two TKA files are global-free functions. Include the pool companion only once.
14There is no filesystem, daemon, persistence, compaction, network configuration, or concurrency in
15this unit. Callers serialize pool access and persist a successful transaction before publishing it.
16
17## Model API
18
19Unless stated otherwise, byte buffers have capacity 65536 and lengths are `ulong`.
20Lengths 0–65536 are successful; errors are 65537 (typed CBOR), 65538 (resource limit),
2165539 (static validation), 65540 (signature), 65541 (parent/key/state), 65542 (not initialized,
22transaction misuse, or no sync intersection). Success/error must be checked before consuming output.
23
24* `tkamodel(input,n,schema,out,keep)` decodes a complete typed object and reconstructs its encoding.
25 Schemas: 1 AUM, 2 Key, 3 State, 4 AUM signature. `keep=0` gives canonical serialization;
26 `keep=1` is an internal typed representation retaining empty-but-non-nil optional values.
27 In particular an empty metadata map is not interchangeable with nil during UpdateKey validation.
28 The output is unchanged on failure. Input and output must be distinct arrays.
29* `tkadec(input,n,out)` is canonical AUM reconstruction. Unknown fields are checked for CBOR
30 well-formedness then dropped; non-shortest encodings, reordered maps, decimal field-name text keys,
31 and integer arrays for byte slices are accepted as upstream accepts them. Duplicates and typed
32 errors reject. Hashing never uses received bytes directly.
33* `tkahash(input,n,sig,out32)` returns 0 or an error. `sig=0` computes AUM Hash, `sig=1` SigHash.
34* `tkavalid(input,n)` returns 0 or an error for upstream StaticValidate, separate from authorization.
35 Unknown AUM kinds are valid forward-compatible no-ops, not an unsupported-version error.
36* `tkatrans(aum,n,state,sn,out,genesis)` verifies and applies to a typed State, returning its new
37 encoded length. `genesis=1` is only for bootstrap, and skips parent matching. On failure the caller
38 must discard `out`; the input state is never changed. All signatures must name trusted keys and
39 verify under ZIP-215, even when another signature is valid. Duplicate signatures are valid but
40 count once for fork weight. The last key cannot be removed. Checkpoints preserve both StateIDs.
41
42Internal token helpers require a successfully normalized model and successful `cbrdec`; they are
43not hostile-byte entry points. Public lengths are checked before CBOR or cryptographic calls.
44The cryptographic implementation is variable-time and has not been constant-time audited.
45
46## Authority API
47
48Two independent authority slots permit bounded in-process synchronization. `tkaselect(slot)` selects
490 or 1 (returns 0 or resource error). `tkareset()` explicitly clears the selected slot. A slot holds
50128 immutable AUM nodes, each with up to 65536 encoded AUM bytes and 65536 state bytes. The two slots
51reserve approximately 32 MiB plus metadata globally; fixed-size per-operation scratch lives on the
52Omega stack. State keys are bounded at 512 (including AddKey), disablement values at 32, and key
53metadata at 512 UTF-8 bytes. Input CBOR retains its existing depth16/array4096/map1024 limits.
54These are resource errors where tighter than upstream; no eviction or hidden history truncation occurs.
55
56* `tkaboot(input,n)` accepts a signed checkpoint into an empty authority, returning 0 or error.
57 Later checkpoints with a non-nil parent may bootstrap, just as upstream permits.
58* `tkainform(input,spans,count)` accepts a batch atomically. `spans` is `ulong[256]`, alternating
59 offset,length for at most128 messages in one input buffer. Parents precede children. On any error,
60 the visible node count, head, states and key table remain unchanged. Already-stored canonical hashes
61 are idempotent and skip static/signature revalidation, matching upstream.
62* For a batch larger than one input buffer, `tkabegin()`, successive `tkastage(input,n)`, and
63 `tkacommit()` provide the same transaction. A failed stage automatically aborts the entire batch;
64 explicit `tkaabort()` is also available. The caller must not query or interleave other operations
65 while staging.
66* `tkahead(out32)` returns 0 or error. `tkacurrent(out)` and `tkastate(hash32,out)` return the encoded
67 current state or a state at any retained branch node; canonicalize with schema3 for wire output.
68* `tkakeys(out16384)` returns the count of concatenated 32-byte Ed25519 public keys, or error.
69 This is the trusted-key table for `nksauth`; regenerate after a committed head change. Keys with
70 malformed public lengths (which upstream static validation allows) cannot authorize signatures
71 and are not exported.
72* `tkaoffer(out)` writes head followed by ancestor hashes and returns the total hash count.
73 Samples occur at absolute depths4,16,64; oldest is appended unconditionally, including an oldest
74 already sampled at an exact sampling boundary. A 128-node DAG cannot reach the next sample256.
75* `tkainter(offer,count,mode1)` returns the intersecting node index or error. `mode1[0]` is0 for
76 up-to-date,1 for head intersection,2 for tail intersection. Offers contain at most2048 hashes.
77* `tkamissing(offer,count,nodes128)` returns a count of ordered local node indices. Fetch each AUM
78 using `tkaget(index,0,out)`, then canonicalize with schema1 for transport. Only the chosen primary
79 continuation is sent, not every off-chain branch. An equal head returns no updates.
80
81The fork rule is highest unique signer vote sum, then RemoveKey over non-RemoveKey, then lowest
82canonical AUM hash bytewise. Cached state at every node makes arbitrary retained-branch state lookup
83bounded, and avoids replay during signature verification. A checkpoint can replace keys and disablement
84values but cannot change the authority IDs.
85
86## Tests
87
88Run `TKA_GO=/path/to/go1.26.8 sh om/tka/test/run.sh /path/to/pinned/omc` from the repository.
89`tools/omc.sh` supplies the pinned compiler when omitted. Requirements: ARM64 Linux, Python3,
90POSIX shell, Go>=1.26.5, and dependencies pinned in `test/oracle/go.mod` and `go.sum`.
91
92The Go oracle imports the real pinned `tailscale.com/tka` and emits deterministic commands and expected
93records. The Omega driver executes those same commands. Scenarios cover bootstrap and later-checkpoint
94bootstrap, add/update/remove/checkpoint, state lookup, StateID rejection, unknown kinds, untrusted and
95invalid signatures, unknown parents, batch rollback, duplicates, vote and hash fork ties, last-key
96removal, sync intersections, exact ancestor sampling boundaries, and convergence. Explicit bounded-profile
97cases check 128-node exhaustion, capacity-failure rollback, and rejection of a 513th key. Existing CBOR
98structure/hostile/fuzz AUM and State corpora are re-judged through the typed model (not merely generic
99CBOR well-formedness). A signature-verification mutant must run to normal completion with the same
100record count and at least one changed result; traps, signals, or an incomplete run fail the harness.
101The focused suite was executed with Go1.26.8 and the pinned compiler: **PASS, 10,691 differential
102records**, and the signature mutant completed all 10,691 records with four differences. The separate
103cross-unit revocation driver also completed successfully: a direct node signature authorizes after
104bootstrap and rejects after its trusted key is removed by a signed AUM.
105
106`test/revocation.om` is compiled with both authority and node-signature units by the harness.
107The oracle's `--fixture` mode emits JSON with hex `genesis`, `removal`, `signature`, and raw32-byte
108`node` fields. It constructs the signed pubkey through upstream NodePublic.MarshalBinary (including
109the `np` prefix) and asserts upstream authorization before, and rejection after, revocation.
110For standalone use: run `go run -mod=readonly . --fixture` in `test/oracle`.
111
112Fixed-array hash decoding follows upstream padding/truncation semantics, while byte slices preserve
113nil versus empty for serialization. Static key-ID equality follows Go bytes.Equal, which treats nil
114and empty as equal; these semantics have dedicated typed-model cases.
115An empty-but-present update metadata map is exercised through explicit wire bytes: it clears
116metadata, then replay of its canonically omitted form is accepted by the already-stored hash without
117revalidating the now-missing update field.
118The corpus also exercises all 256 simple-number encodings in seven typed destinations. As upstream
119fxamacker `fillPositiveInt` specifies, major7 simple values with additional-information0–19 or24
120populate unsigned fields and byte-array elements; Boolean values remain type errors, and null or
121undefined leave zero values.
122
123### Third-party material and notices
124
125Protocol behavior and translated algorithms derive from Tailscale v1.102.0, commit
126`35283c95445fb198af1ce708dac05714bdfaa037`, fetched2026-10-25. Copyright Tailscale Inc & contributors,
127BSD-3-Clause; the upstream notice is shipped verbatim in `tailscale.LICENSE`. The Go decoder options
128are transcribed from `tka/tka.go` and covered by that notice. Other Go code is only an external test
129oracle. Shared CBOR vectors retain their provenance and notices in `om/cbor`.