@inversealtruism/cairnx-core 0.2.4 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CONVENTION.md CHANGED
@@ -1,13 +1,17 @@
1
1
  # CairnX Convention v1
2
2
 
3
- **Status:** v2.9 (normative; v2.9 pending activation at `V29_HEIGHT`, see §32; v2.8 activated at 60 000, crossed 2026-07-23; supersedes the 2026-06-10 v1.0 draft) · **Domain:** `cairnx:v1` · **Base activation:** 29 860
3
+ **Status:** v2.9 (normative; v2.9 activated at `V29_HEIGHT` = 88 000, crossed 2026-08-31, see §32; v2.8 activated at 60 000, crossed 2026-07-23; supersedes the 2026-06-10 v1.0 draft; §33 to §41 carry no gate and move no state) · **Domain:** `cairnx:v1` · **Base activation:** 29 860
4
4
 
5
5
  **Version ladder** (each gate non-retroactive: below it, behavior + canonical hashes are byte-identical to history):
6
6
  v1.1 @ 29 960 · v1.2 @ 30 300 · v1.3 @ 31 100 · v1.4 @ 31 400 · v1.5 @ 32 000 · v1.6 @ 33 600 (§19) ·
7
7
  v1.7 @ 34 000 (§20) · v1.9 @ 36 700 (§22) · v2.0 @ 38 400 (§23) · v1.8 @ 40 000 (§21) · v2.1 @ 40 100 (§24) ·
8
8
  v2.2 @ 41 300 (§25) · v2.4 @ 46 400 (§27) · v2.5 @ 46 440 (§28) · v2.6 @ 46 480 (§29) · v2.7 @ 46 520 (§30) ·
9
- v2.3 @ 52 000 (§26) · v2.8 @ 60 000 (§31) · v2.9 @ 88 000 (§32, PENDING activation).
9
+ v2.3 @ 52 000 (§26) · v2.8 @ 60 000 (§31) · v2.9 @ 88 000 (§32; its replay hash is pinned in `test/vectors/replay-hashes.json`).
10
10
  Sections §19–§32 are the normative semantics for v1.6–v2.9; §5.1 is the byte-level canonical-JSON contract that binds all of them.
11
+ §33 is the rule that turns the chain's blocks into the events every version replays; §34 defines the two hashes
12
+ replicas compare. §35 and §36 are for other applications (their domains, the profile-key registry), §37 states what
13
+ a result proves, §38 how a replica conforms, §39 how the rules change, §40 the reason codes of the applied log
14
+ and of record validation and §41 the token moves of the applied log; none of §33 to §41 has a gate.
11
15
  Activation order is by HEIGHT, not by version number (v1.8 activated after v2.0; v2.3 activates after v2.4–v2.7): a
12
16
  replayer gates each rule on its own height constant, never on "version X implies version Y is active".
13
17
 
@@ -17,9 +21,9 @@ replayer gates each rule on its own height constant, never on "version X implies
17
21
  > recorded history replays byte-identically. Replayers built from this spec MUST use the re-pinned heights above.
18
22
 
19
23
  > **Canonical copy.** This spec ships in the published `@inversealtruism/cairnx-core` package; the source of
20
- > truth is `csd-sdk/packages/cairnx/CONVENTION.md`. Any in-repo mirror (e.g. the `cairnx` app repo) MUST be
21
- > kept **byte-identical** to it on every change: a third-party implementer fetches the *published* copy, so
22
- > it is the one that must never lag the code. Keep the two in lockstep when editing.
24
+ > truth is `csd-sdk/packages/cairnx/CONVENTION.md`. The `cairnx` app repo keeps no copy: its `CONVENTION.md`
25
+ > is a pointer to this file and to the copy in the installed package. A third-party implementer fetches the
26
+ > *published* copy, so it is the one that must never lag the code.
23
27
 
24
28
  CairnX is a meta-asset and exchange convention on Compute Substrate (CSD). It defines fungible
25
29
  tokens and trades, one transaction paying and recording each fill, using **only** the chain's existing `Propose`
@@ -27,8 +31,9 @@ and `Attest` transactions: no fork, no new transaction types, no custodian. Toke
27
31
  enforced by a **pure, deterministic resolver** that any party can run; independent resolvers
28
32
  replaying the same chain converge on identical state.
29
33
 
30
- This document is normative. The reference resolver (`src/resolve.ts`) and its conformance suite
31
- implement exactly what is written here.
34
+ This document is normative. The reference resolver (`src/resolve.ts`), the reference rule of §33
35
+ (`src/events.ts`), the hashes of §34 (`src/hashes.ts`), the reason codes of §40 (`src/codes.ts`) and their conformance
36
+ suites implement exactly what is written here.
32
37
 
33
38
  ---
34
39
 
@@ -39,7 +44,9 @@ Verified against the node source (`compute-substrate` @ v1.x, 2026-06-10):
39
44
  - **C1.** Every input of a tx signs the same global sighash; tx validity requires all signatures.
40
45
  - **C2.** A `Propose`/`Attest` tx's value outputs are unrestricted (only fee floors apply:
41
46
  ≥ 0.25 CSD propose, ≥ 0.05 CSD attest). One tx can pay arbitrary addresses *and* carry an app payload.
42
- - **C3.** `proposer` / `attester` = `hash160(input[0].pubkey)`, stored by consensus.
47
+ - **C3.** `proposer` / `attester` = `hash160(input[0].pubkey)`, stored by consensus. The node accepts input 0
48
+ only when that hash equals the `script_pubkey` of the coin it spends, so for a mined tx it is that coin's
49
+ owner. The txid does not commit the signature script; a reader takes the author from the spent coin (§33.5).
43
50
  - **C4.** `Propose.uri` is a consensus-stored string ≤ **512 bytes** (non-empty); `payload_hash`
44
51
  is a consensus-stored 32-byte value (non-zero).
45
52
  - **C5.** An `Attest` referencing proposal `P` is **consensus-rejected** once
@@ -65,13 +72,16 @@ signatures in v1: anchoring *from your key* is the authorization.
65
72
 
66
73
  ## 3. Common rules
67
74
 
68
- - **Amounts** are strings of decimal integers in base units, `"1"` ≤ x < `2^96`. Resolvers use
69
- arbitrary-precision integers. `decimals` (0–8) is display-only.
75
+ - **Amounts** are strings of decimal integers in base units, `"1"` ≤ x < `2^96`, except an offer's price: its
76
+ `want.value` (§4.4) and its `want.amount` (§11) may be `"0"`. Resolvers use arbitrary-precision integers.
77
+ `decimals` (0–8) is display-only.
70
78
  - **Tickers** match `^[A-Z][A-Z0-9]{2,11}$`.
71
79
  - **Addresses** are `0x` + 40 lowercase hex.
80
+ - **Hashes and ids in records** (`ncommit`'s `commit`, `tmeta`'s `hash`, an offer's `bid`, an `fclaim`'s `offer`) are
81
+ `0x` + 64 lowercase hex (`HASH_RE`); any other form makes the record an invalid no-op (`RECORD_BAD_HASH`).
72
82
  - **Apply order:** events are replayed in consensus order: by block height; within a block,
73
- all `cairnx:v1` proposals in tx order (`pos`), then all attestations on CairnX offers in tx
74
- order. (Mirrors the node’s propose/attest phases, C5.) Remaining ties (same height, phase, pos:
83
+ all `cairnx:v1` proposals in tx order (`pos`), then all attestations on CairnX proposals in tx
84
+ order (the events of §33). (Mirrors the node’s propose/attest phases, C5.) Remaining ties (same height, phase, pos:
75
85
  possible only across indexer quirks, never on a real chain) break by **ordinal (code-unit)
76
86
  comparison of the lowercase `0x`-hex txid**. Ordinal comparison is the ONLY string ordering
77
87
  used anywhere in resolution and serialization: locale-aware collation (e.g. JavaScript's
@@ -79,8 +89,9 @@ signatures in v1: anchoring *from your key* is the authorization.
79
89
  - **Invalid = no-op.** A record that fails any check (schema, balance, state) has **no effect**.
80
90
  Unknown `t` values and `v ≠ 1` are no-ops (forward compatibility). Invalidity never poisons
81
91
  later records.
82
- - **Activation:** anchors below height **29 860** are ignored. (Set just before the first
83
- protocol traffic: the domain had no prior use; the live X2 e2e records ARE the genesis.)
92
+ - **Activation:** anchors below height **29 860** are ignored, and are not events (§33); neither is an
93
+ Attest on such an anchor. (Set just before the first protocol traffic: the domain had no prior use; the
94
+ live X2 e2e records ARE the genesis.)
84
95
  - **Finality:** state derived from blocks < 6 confirmations is provisional (display threshold
85
96
  3, final 6, matching Cairn's site conventions).
86
97
 
@@ -143,7 +154,7 @@ CairnX meaning for deploys. The **deployer** is the anchoring proposer.
143
154
  - `taker` (optional): if present, only this address can fill. **Taker-bound offers are the
144
155
  protected path** (see §6).
145
156
  - The anchoring proposal's **`expires_epoch` is the offer's validity window**: after it, the
146
- chain itself rejects fill attempts (C5), and the resolver releases the lock. Offers SHOULD
157
+ chain itself rejects fill attempts (C5), and the resolver releases the lock (the expiry sweep of §5). Offers SHOULD
147
158
  use short windows (e.g. tip-epoch + 24 ≈ 1 day).
148
159
  - An offer is identified by its **proposal id (txid)**.
149
160
  - `memo` (64 UTF-16 units max) and `ts` are optional free fields with the same rules as
@@ -182,19 +193,50 @@ extension shipped at v1.7 (height 34 000) and uses **`score = 50`** (`SCORE_CLAI
182
193
  ## 5. Resolver state (normative output)
183
194
 
184
195
  ```
185
- tokens: ticker → { deployId, deployer, name, decimals, supply, minted, mint, mintLimit, height }
196
+ tokens: ticker → { ticker, deployId, deployer, name?, decimals, supply, minted, mint, mintLimit?, height, tmeta? }
186
197
  balances: ticker → address → { available, locked }
187
- offers: offerId → { seller, give, want, taker?, status: open|filled|cancelled|expired,
188
- expiresEpoch, height, fill?: { buyer, txid, height, paid } }
189
- events: ordered log of applied/no-op decisions (for explorers & audit; INFORMATIONAL,
190
- excluded from the canonical surface; its reason strings are diagnostics, not protocol)
198
+ names: name → { name, owner, claimId, height, effectiveHeight, locked, addr?, viaFill?, profile?,
199
+ paidThroughEpoch?, expired? }
200
+ or, for a pending reservation (§28):
201
+ name → { name, owner, claimId, height, effectiveHeight, locked, pending, finalizeBy }
202
+ offers: offerId → { id, seller, give, want: { value, payto } | { ticker, amount, payto }, taker?,
203
+ status: open|filled|cancelled|expired, expiresEpoch, height, feeBps,
204
+ min?, paid?, delivered?, fills?, bid?, claimedBy?, claimUntilHeight?, claimTxid?,
205
+ fill?: { buyer, txid, height, paid, fee, got? } }
206
+ bids: bidId → { id, bidder, want, give: { value }, status: open|cancelled|expired|done,
207
+ expiresEpoch, height, offers }
208
+ feesPaid: the protocol fees owed by applied records (§10), a decimal string
209
+ events: ordered log of applied/no-op decisions { height, pos, id, kind, ok, code, note?, moves? } (for explorers &
210
+ audit; INFORMATIONAL, excluded from the canonical surface; each entry's `code` is stable (§40), its `note`
211
+ text a diagnostic, and an applied record that moved tokens carries its `moves` (§41))
191
212
  ```
192
213
 
214
+ An address whose `available` and `locked` are both 0 is left out of `balances`, and so is a ticker with no address
215
+ remaining. `want.payto` is always present: the record's `payto`, or the seller when the record has none.
216
+
217
+ **Fill records.** A whole fill sets `fill` once. Its `paid` is what the fill's transaction pays to `want.payto` (the
218
+ `paidTo` sum of §33.4), overpayment included, and so the maker rebate as well when `payto` is the seller (§19); for a
219
+ token-priced fill it is `want.amount`. Its `fee` is the fee the fill owed (§10, §14, §19). A partial fill (§12) appends
220
+ `{buyer, txid, height, paid, fee, got}` to `fills`, with `paid` its effective payment `x` and `got` the give units it
221
+ delivered; the partial fill that completes the offer also sets `fill` to that same entry, `got` included.
222
+
223
+ **Expiry in the state.** Before each event at height h the resolver expires every open offer and bid whose effective
224
+ expiry epoch (§24, §25) is below `epochOf(h)`, releasing an offer's give, and deletes every reservation (§28) and
225
+ recapture reservation (§29) whose `finalizeBy` is below h. After the last event, and after the deferred cancels of its
226
+ block (§16), it runs the same sweep once more at `tipHeight + 1`. So the state at a tip shows an offer or bid whose
227
+ effective expiry epoch, as the sweep at `tipHeight + 1` computes it, is `epochOf(tipHeight)` as `expired` when
228
+ `tipHeight` is the last height of that epoch (`tipHeight mod 30 = 29`), and as `open` at every earlier tip of the
229
+ epoch. For an offer or bid anchored below V22 that sweep applies the §24 cap once `tipHeight + 1` reaches V21
230
+ (40 100), that is from tip 40 099 on. A name's `expired` (§17) is read at the tip's own epoch: it is present when
231
+ `epochOf(tipHeight) > paidThroughEpoch + NAME_GRACE_EPOCHS`.
232
+
193
233
  **Canonical state (format 2, normative):** the canonical surface is
194
234
  `{tipHeight, tokens, balances, names, offers, bids, feesPaid}`: the event log is excluded.
195
- Serialization is **canonical JSON**: object keys sorted in ordinal (code-unit) order at every
196
- depth, no insignificant whitespace, UTF-8, all amounts as decimal strings (no floats anywhere),
197
- booleans/numbers in their shortest JS form. Two resolvers fed the same chain prefix MUST produce
235
+ Serialization is **canonical JSON** in the state form of §5.1: object keys sorted in ordinal (code-unit) order at every
236
+ depth, except that keys which are array indices (the canonical decimal of an integer in [0, 2^32 − 2]: an all-digit
237
+ name, an all-digit profile key) come first in ascending numeric order (§5.1 A2); arrays keep their order (`fills` and a
238
+ bid's `offers` in apply order); no insignificant whitespace, UTF-8, all amounts as decimal strings (no floats anywhere),
239
+ booleans/numbers in their shortest JS form. Two resolvers fed the events of §33 for the same chain prefix MUST produce
198
240
  byte-identical canonical state; `sha256(canonicalState)` at the activation heights is pinned in
199
241
  `test/vectors/replay-hashes.json`, and `test/vectors/cases.json` carries language-neutral replay
200
242
  vectors a third-party implementation must reproduce. (Format 1, pre-2026-06-12, included the
@@ -244,19 +286,24 @@ once a replay hash is pinned over data that exercises them, so they are stated h
244
286
  `_js_obj_key_order`/`_js_stringify` in `conformance/cairnx_ref.py`); a third impl MUST reproduce both.
245
287
  - **A3: Field types (bare number/boolean vs decimal string vs identity string).** Canonical state mixes
246
288
  raw JSON integers and booleans with decimal-string amounts and raw identity strings. Emit as **bare
247
- integers**: `decimals, height, effectiveHeight, expiresEpoch, feeBps, tipHeight, paidThroughEpoch`, and
248
- (v1.7) `claimUntilHeight` (all JS-safe, < 2^53). Emit as **bare booleans**: `locked, viaFill, expired`.
249
- Emit as **decimal strings**: `supply, minted, mintLimit, feesPaid`, every `balances.*.available`/`.locked`,
250
- `want.value`, `want.amount`, `min`, `paid`, `delivered`, and each fill's `paid`/`.fee` (plus `.got` ONLY on
251
- a partial `fills[]` entry; see the fill shapes below). Emit as **raw 0x-hex identity strings**: the offer
252
- `id` (32-byte txid), the name `claimId` (32-byte anchor txid, present on **every** name), and (v1.7) the
253
- offer `claimedBy` (20-byte addr). Emit as a nested **object**: the name `profile` (v1.9 nprofile: a flat
254
- string→string map). **Two distinct fill shapes (the `got`-presence rule):** a whole-offer fill is the
255
- singular object `fill` = `{buyer, txid, height, paid, fee}` and **OMITS `got`**; a partial-fillable (`min`)
256
- offer instead carries an **array** `fills`, each entry `{buyer, txid, height, paid, fee, got}` **WITH
257
- `got`** (`got` = the give-asset units delivered by that partial). An implementer who adds `got` to the
258
- singular `fill` (or drops it from a `fills[]` entry) forks `sha256(canonicalState)`. Never serialize an
259
- amount as a number or an `f64`; never stringify an integer field.
289
+ integers**: `decimals, height, effectiveHeight, expiresEpoch, feeBps, tipHeight, paidThroughEpoch, finalizeBy`,
290
+ and (v1.7) `claimUntilHeight` (all JS-safe, < 2^53). Emit as **bare booleans**: `locked, viaFill, expired,
291
+ pending`. Emit as **decimal strings**: `supply, minted, mintLimit, feesPaid`, every
292
+ `balances.*.available`/`.locked`, an offer's `give.amount`, `want.value`, `want.amount`, `min`, `paid` and
293
+ `delivered`, a bid's `want.amount` and `give.value`, and each fill entry's `paid`, `fee` and `got` (see the fill
294
+ shapes below). Emit as **raw 0x-hex identity strings**: the 32-byte ids, that is the offer and bid `id`, the token
295
+ `deployId`, the name `claimId` (the anchor txid, present on **every** name), a fill's `txid`, the offer `bid` and
296
+ (v2.8) `claimTxid`, and the token `tmeta` (a content hash); and the 20-byte addresses `deployer`, `owner`, `addr`,
297
+ `seller`, `taker`, `want.payto`, `bidder`, `buyer` and (v1.7) `claimedBy`. Emit as plain strings: `ticker`, the
298
+ token `name`, `mint`, a name's `name` (also `give.name` and a bid's `want.name`) and `status`. Emit as **arrays**:
299
+ an offer's `fills` and a bid's `offers` (offer ids), in apply order. Emit as a nested **object**: the name `profile`
300
+ (v1.9 nprofile: a flat string→string map). **Two fill shapes (the `got`-presence rule):** a whole fill (of an offer
301
+ without `min`) is the singular object `fill` = `{buyer, txid, height, paid, fee}` with **no** `got`; a
302
+ partial-fillable (`min`) offer carries an **array** `fills`, each entry `{buyer, txid, height, paid, fee, got}`
303
+ **with** `got` (`got` = the give-asset units delivered by that partial), and the partial fill that completes it also
304
+ sets the singular `fill` to that same entry, `got` included (§5). An implementer who adds `got` to a whole fill, or
305
+ drops it from a `fills[]` entry or from a completed partial offer's `fill`, forks `sha256(canonicalState)`. Never
306
+ serialize an amount as a number or an `f64`; never stringify an integer field.
260
307
  > **⚠ v1.7/v1.9 are part of this byte contract on every live tip past their gate** (`V17_HEIGHT=34000`
261
308
  > claims, `V19_HEIGHT=36700` profiles). A second-language resolver built to an earlier copy of this list
262
309
  > (omitting `claimedBy`/`claimUntilHeight`/`claimId`/`profile`/`fills`) **forks `sha256(canonicalState)`
@@ -264,11 +311,14 @@ once a replay hash is pinned over data that exercises them, so they are stated h
264
311
  > `replay-hashes.json` at **every activation height through V20**: incl. 34 000 claims, 36 700 profiles,
265
312
  > 38 400 grace; V18/V21 auto-pin once the chain tip crosses them. The static `cases.json` bar additionally
266
313
  > pins the V20/V21/nprofile/name-op/lapse byte-contract with no live node required.)
267
- - **A4: Optional fields are OMITTED, never `null`.** A key whose value is absent is dropped entirely
268
- (`addr, viaFill, min, bid, taker, paidThroughEpoch, expired`, token `name`/`mintLimit`/`tmeta`, and the
269
- v1.7/v1.9 optionals `claimedBy`/`claimUntilHeight` (omitted unless the offer is claimed), `fill`
270
- (omitted until first filled), `fills` (only on a `min` offer), `profile` (only when an nprofile is set)).
271
- Never emit `"addr":null`.
314
+ - **A4: Optional fields are OMITTED, never `null`.** A key whose value is absent is dropped entirely: the token
315
+ `name`, `mintLimit` and `tmeta`; the name `addr`, `viaFill`, `profile` (only when an nprofile is set, at v1.9+
316
+ tips), `paidThroughEpoch` (on every name at v1.5+ tips except a pending reservation), `expired`, and `pending` and
317
+ `finalizeBy` (only on a pending reservation, §28); the offer `taker`, `min`, `paid`, `delivered` and `fills` (only on
318
+ a `min` offer, from its creation), `bid`, `claimedBy` and `claimUntilHeight` (from the offer's first claim grant on,
319
+ and kept after the hold ends and after the offer closes, §20), `claimTxid` (from its first fclaim grant on, §31) and
320
+ `fill` (until a whole fill, or the partial fill that completes the offer); and a whole fill's `got`. A zero balance
321
+ is left out as §5 says. Never emit `"addr":null`.
272
322
  - **A5: The acceptance gate is a byte-exact round-trip (stronger than the hash check).** A record anchor
273
323
  is accepted iff **both** `canonicalJson(JSON.parse(uri)) === uri` (byte-for-byte) **and**
274
324
  `sha256(uri) === payload_hash`. The round-trip is what rejects duplicate keys, leading-zero amounts,
@@ -339,9 +389,10 @@ cap: ecosystem doc 16 §4; these are NOT in canonical state today.)*
339
389
  payment), so a losing claimer forfeits only the 0.05 CSD attest fee. On that basis v1.7 safely
340
390
  **re-opens** untaken CSD offers via claim-to-fill (§20), and v2.0/§23 bounds its late-fill edge.)
341
391
  - **No unconfirmed chaining (no CPFP).** The mempool only accepts txs whose inputs exist in the
342
- confirmed UTXO set: you cannot spend change that hasn't been mined. Sequential CairnX actions
343
- from one key require one confirmation between them; client software must serialize and surface
344
- this ("next action available after 1 conf").
392
+ confirmed UTXO set: you cannot spend change that hasn't been mined. A key's next action needs a
393
+ confirmed coin: with one coin, one confirmation between actions; a key holding several confirmed
394
+ coins can anchor several records in one block (§16). Client software that spends one coin must
395
+ serialize its actions and surface this ("next action available after 1 conf").
345
396
  - **No native-CSD pools.** CSD itself cannot be locked by convention (real UTXOs obey only
346
397
  keys). CairnX trades CSD↔token atomically per-trade; it does not and cannot pool CSD.
347
398
  - **Reorgs:** state is a pure function of the chain; resolvers recompute (or roll back) on
@@ -377,25 +428,33 @@ owned purely on-chain: register, hold, point it at an address, transfer, or sell
377
428
 
378
429
  - **Charset:** lowercase ASCII only: `^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$`, **1–32 chars**,
379
430
  no leading/trailing hyphen (single- and double-character premium names are valid and priced at
380
- the top of the fee curve). ASCII-only **eliminates the entire homograph/confusable attack
381
- class** (no Unicode → no look-alikes) and is trivially deterministic for every indexer.
431
+ the top of the fee curve). ASCII-only removes the mixed-script homograph class (no Unicode, so
432
+ no Cyrillic U+0430 in place of a Latin `a`) and is trivially deterministic for every indexer. It
433
+ does not remove look-alikes within ASCII: `paypa1` and `paypal` are distinct, valid names.
382
434
  Reserved: `csd treasury admin official root www support` (`cairn`/`cairnx` are deliberately
383
435
  NOT reserved: the operator registered them as ordinary, tradeable names).
384
436
  - **`name` (claim):** `{v:1,t:"name",name,salt?}`. Owner = anchoring proposer. **Lowest
385
- effective-anchor (height, pos, id) wins.** Requires the registration fee (§ below).
437
+ effective anchor (effHeight, pos, id) wins**, numeric on `effHeight` and `pos`, ordinal (code-unit) on `id`:
438
+ `effHeight` is the claim's own height, or a reveal's commit height (below); `pos` and `id` are always the claim or
439
+ reveal record's own position and transaction id, never the commit's. Requires the registration fee (§ below).
386
440
  - **Direct claim** (no `salt`): effective height = claim height. Simple, instant; front-runnable.
387
- - **Commit-reveal** (`salt` present): a prior `ncommit` of `sha256({t:"cairnx:name:commit:v1",
388
- name,salt,owner})` must exist at a strictly lower height within `COMMIT_MAX_BLOCKS` (8 epochs).
441
+ - **Commit-reveal** (`salt` present): `salt` is 16 to 128 hex digits in either case (`SALT_RE`,
442
+ `^[0-9a-fA-F]{16,128}$`); any other `salt` makes the record an invalid no-op (`RECORD_BAD_SALT`). A prior
443
+ `ncommit` of `sha256({t:"cairnx:name:commit:v1", name,salt,owner})` must exist at a strictly lower height within
444
+ `COMMIT_MAX_BLOCKS` (8 epochs): with the commit height the LOWEST height at which that commit hash was anchored,
445
+ the reveal is valid only when `0 < revealHeight − commitHeight ≤ COMMIT_MAX_BLOCKS` (`REG_COMMIT_MAX_BLOCKS = 8`
446
+ blocks from v2.5, §28). A later anchoring of the same commit hash leaves that height as it is, so it does not
447
+ reopen a window that has passed; a retry after the window needs a fresh salt.
389
448
  The reveal **back-dates** its effective height to the commit height, so a committer beats any
390
449
  direct-claim squatter who acts in between (the reveal **displaces** them). This is the
391
450
  front-run defense (ENS/Namecoin/Runes pattern adapted to a fee-ordered chain).
392
451
  - **`ncommit`:** `{v:1,t:"ncommit",commit}`: the commit hash (binds name+salt+owner, so it can't
393
452
  be reused by another address). Cheap; the reg fee is paid at reveal.
394
453
  - **`nxfer`:** `{v:1,t:"nxfer",name,to}`: owner gifts the name. Clears the resolver record. Fails
395
- while the name is locked by an open offer.
454
+ while the name is locked by an open offer, and on a pending reservation (§28).
396
455
  - **`nset`:** `{v:1,t:"nset",name,addr}`: owner points the name at an address (the resolver
397
- record). Reverse resolution (address → names owned) is computed by the resolver.
398
- - **Selling a name:** an `offer` with `give:{name}` (instead of `{ticker,amount}`). Anchoring it
456
+ record). Fails on a pending reservation (§28). Reverse resolution (address → names owned) is computed by the resolver.
457
+ - **Selling a name:** an `offer` with `give:{name}` (instead of `{ticker,amount}`), not on a pending reservation (§28). Anchoring it
399
458
  **locks** the name (can't transfer/re-offer); a `fill` transfers ownership to the buyer and pays
400
459
  the seller (+ protocol fee), atomically, in one tx; cancel/expiry release the lock.
401
460
  - **Honest limits (v1.1, superseded):** names were **perpetual** through v1.4 (the registration fee
@@ -418,8 +477,12 @@ bearing action is a **no-op unless its own transaction pays the fee to the treas
418
477
 
419
478
  Mint, transfer, name-xfer, name-set, offer, commit and cancel pay only the chain's own anchor fee
420
479
  (to miners), not a protocol fee. An offer's `want.payto` may not be the treasury (keeps the
421
- payment and fee output buckets distinct). The resolver tracks `feesPaid` (total observed to the
422
- treasury), recomputable by anyone, like all CairnX state.
480
+ payment and fee output buckets distinct); since `payto` defaults to the seller, an offer the treasury anchors names
481
+ another `payto`. The resolver tracks `feesPaid`, recomputable by anyone like all CairnX state: the sum of the fees
482
+ that applied fee-bearing records owed, not of what was paid to the treasury. Each applied deploy (from 29 960),
483
+ registration or finalize, renewal and recapture adds its fee or premium, and each applied CSD-priced fill, whole or
484
+ partial, adds its trade fee (§19); an overpayment, a treasury output on a record that owes no fee and the outputs of a
485
+ refused record add nothing, and the in-kind fee of a token-priced fill is not counted (§14).
423
486
 
424
487
  ---
425
488
 
@@ -440,6 +503,9 @@ An offer's `want` may now be a **token amount** instead of a CSD value:
440
503
  - `want.ticker` must exist at fill time (checked at apply, like every balance rule); a
441
504
  token-priced offer over an unknown ticker simply can never fill until that ticker exists.
442
505
  `give.ticker ≠ want.ticker`. `give` may also be a **name** (sell a name for tokens).
506
+ - `want.amount` may be `"0"` (§3), as `want.value` may (§4.4). Such an offer is filled for nothing: the fill debits
507
+ `0 + ceil(0)` = 0, so an attester holding none of `want.ticker` fills it (with the marker below, and as its taker
508
+ when it is taker-bound).
443
509
  - Anchoring locks `give` exactly as in v1 (§4.4). `want.payto` (default seller) receives the
444
510
  want-tokens; it may not be the treasury.
445
511
  - **Fill** = an `Attest` with `score = 100` **and `confidence = 1 000 000`** whose attester's
@@ -479,10 +545,13 @@ A CSD-priced **token** offer may opt into partial fills with `min`:
479
545
  `deliveredCum' = floor(give.amount × paidCum' / want.value)`: each fill delivers
480
546
  `deliveredCum' − deliveredCum`. The final fill (`paidCum' = want.value`) therefore delivers
481
547
  exactly the undelivered remainder; rounding dust never strands in the lock.
548
+ - A partial fill that would deliver nothing (`deliveredCum' = deliveredCum`) is a no-op (`FILL_ZERO_DELIVERY`): it is
549
+ not appended, `paid`, `delivered` and `feesPaid` do not move, and its payment stays with `payto` (§4.5).
482
550
  - `fee = ceil(1% × x)` to the treasury in the same tx, per fill.
483
551
  - The offer stays `open` until `paidCum = want.value` → `filled`. Cancel/expiry release the
484
552
  undelivered remainder to the seller; completed partial fills stand.
485
- - Each fill is appended to the offer's `fills[]` (buyer, txid, height, paid, got, fee).
553
+ - Each applied partial fill is appended to the offer's `fills[]` (buyer, txid, height, paid = `x`, got, fee); the one
554
+ that completes the offer is also its `fill` (§5).
486
555
  - Open partially-fillable offers race like v1 open offers (fee auction, §6), but losing a
487
556
  race now only costs the loser the *overlap*: their payment still buys whatever remained.
488
557
  Wallets must still warn on open-offer fills.
@@ -494,10 +563,16 @@ A CSD-priced **token** offer may opt into partial fills with `min`:
494
563
  ```
495
564
 
496
565
  Cancels **all of the proposer's open offers anchored strictly earlier in apply order**, releasing
497
- their locks, optionally filtered to one `give` asset (`ticker` or `name`, at most one). Without
566
+ their locks, optionally filtered to one `give` asset (`ticker` or `name`, at most one), except what §31 exempts: a
567
+ taker-bound offer anchored at V28 or above is not a target (Lane B), and from V28 the block-boundary flush skips a
568
+ target under a live fclaim hold (Correction 2). Without
498
569
  cheap mass-cancel a market maker cannot keep a ladder of quotes honest (per-offer cancel = one tx
499
- each: the 0x `minValidSalt` lesson). Anchor an `ocancel`, then re-post the fresh ladder, even in
500
- the same block (proposals apply in tx order, so a later-pos ladder survives an earlier-pos cancel).
570
+ each: the 0x `minValidSalt` lesson). Anchor an `ocancel`, then re-post the fresh ladder in a later block. From v1.4
571
+ (height 31 400, §16) an `ocancel`'s effect waits for the end of its block, so the give it releases stays locked for the
572
+ rest of that block: an offer of that give later in the same block is refused (`TOKEN_BALANCE_LOW` for tokens,
573
+ `NAME_LOCKED` for a name) and its anchor fee is spent for nothing. A same-block offer at a later position is not a
574
+ target of the `ocancel` (its targets are fixed when it applies), so it stands when the proposer's available balance
575
+ covers it without the released amount.
501
576
 
502
577
  **Self-fills** (attester == seller) are **valid** and pay the protocol fee like any fill: wash
503
578
  trading is self-punishing, and a no-op rule would just complicate determinism. **Fill races on
@@ -520,12 +595,17 @@ of the book is instead built from **bids**, on-chain discovery records:
520
595
  - `memo` (64 UTF-16 units max) and `ts` are optional free fields, same rules as 4.3; `ts` MUST
521
596
  be a JS-safe integer (A8).
522
597
  - **Fulfillment** is the two-step RFQ: the asset owner anchors a **taker-bound offer**
523
- (`taker = bidder`, price ≤ bid) optionally tagged `"bid":"<bidId>"`; the bidder's client
598
+ (`taker = bidder`, price ≤ bid) optionally tagged `"bid":"<bidId>"` (the bid's id, §3); the bidder's client
524
599
  detects the responding offer and fills it atomically. Two anchors + one fill: the
525
600
  scriptless ceiling for buy-side flow.
526
- - The resolver tracks `bids` (open/cancelled/expired) and links responding offers
527
- (`offer.bid` → `bid.offers[]`). A bid whose linked offer is **filled by the bidder** is
528
- marked `done` (purely informational).
601
+ - The resolver tracks `bids` (open/cancelled/expired/done). An applied offer whose `bid` names a bid in `bids` is
602
+ appended to that bid's `offers` (in apply order) whatever its taker, its price and the bid's status: taker = bidder
603
+ and price ≤ bid describe an honest answer, not a condition of the link. An offer whose `bid` names no bid when it
604
+ applies is created with its `bid` and is never added to a bid's `offers`, then or later. A fill that closes an offer
605
+ carrying `bid` (a whole fill, or the partial fill that completes it) looks that id up in `bids` at the fill, not
606
+ through `offers`, and marks the bid `done` when it exists, the buyer is its bidder and it is still `open`; a bid
607
+ already cancelled or expired keeps its status, and a bid anchored after the offer naming it can be `done` with empty
608
+ `offers` (purely informational).
529
609
  - No protocol fee on bids (the anchor fee to miners is the spam price; the trade fee is paid
530
610
  when the responding offer fills).
531
611
 
@@ -633,10 +713,10 @@ From height **31 400**:
633
713
  after the flush.
634
714
  - **Why deferral, not reordering:** moving cancels after fills in the sort would break the
635
715
  global ordered loop and the "offers settle before fills" invariant for every other record
636
- type. Deferring only the effect keeps apply order intact. The one non-physical edge (a
637
- same-key `ocancel`-then-relist in one block observing pre-flush lock state) **cannot occur
638
- on-chain**: anchor inputs must be confirmed (no CPFP), so one key cannot chain two anchors
639
- into a single block.
716
+ type. Deferring only the effect keeps apply order intact. A relist by the same key later in
717
+ the cancel's block sees the lock state before the flush, so a relist that needs the give the
718
+ cancel releases is refused (§12b). One key can anchor several records in one block, each spending
719
+ its own confirmed coin.
640
720
  - **Determinism:** the deferred-cancel list is built and flushed in apply order, so the state
641
721
  (and the event log) remains a pure function of the chain prefix. Non-retroactive: pre-v1.4
642
722
  blocks never defer, so all historical replay is byte-identical.
@@ -650,17 +730,23 @@ lose more than the anchor fee: not to another buyer (race), and not to the selle
650
730
  **once, forever**: squatting is free to carry, and lapsed projects strand names permanently.
651
731
  From height **32 000** every name is a **lease**:
652
732
 
653
- - **Term:** a claim (or premium re-claim) is paid through `claimEpoch + 8 760` epochs (≈ 1 year).
733
+ - **Term:** a claim (or premium re-claim) is paid through `claimEpoch + 8 760` epochs (≈ 1 year), with `claimEpoch`
734
+ the epoch of the claim or reveal record's own height, not of its back-dated effective height (from v2.5 the lease
735
+ starts at the finalize instead, §28, §29).
654
736
  Names claimed before v1.5 are **grandfathered** one full term from activation
655
737
  (`epochOf(32 000) + 8 760`), computed lazily, no state rewrite at the boundary.
656
738
  - **`nrenew` `{v:1,t:"nrenew",name}`:** extends the lease one term from its CURRENT end. Valid
657
739
  from **anyone** while the lease is live (third-party gifting, ENS-style) iff the same tx pays
658
- `nameRegFee(name)` to the treasury. A renewal never changes ownership.
740
+ `nameRegFee(name)` to the treasury. A renewal never changes ownership. A pending reservation (§28) holds no lease and
741
+ is not renewed, by anyone.
659
742
  - **Grace (720 epochs ≈ 30 days):** past `paidThroughEpoch`, only the **owner** may renew;
660
743
  otherwise a squatter could extend a lapsing name they intend to take.
661
744
  - **Lapse → decaying-premium recapture:** past grace the name is unowned again. Anyone may claim
662
- it by paying `expiredClaimFee(name, epochsPastGraceEnd)`: `nameRegFee × 20` linearly decaying
663
- to `× 1` over 720 epochs (pure integer function: deterministic everywhere). The re-claim is a
745
+ it by paying `expiredClaimFee(name, e) = nameRegFee(name) × m(e)`, priced at height `h` (the finalize from v2.6,
746
+ §29), where `e = epochOf(h) − (paidThroughEpoch + 720)` counts the epochs past the grace end (at least 1, since the
747
+ name has lapsed) and, in integer division, `m(e) = 1 + floor(19 × (720 − e) / 720)` for `e < 720` and `m(e) = 1`
748
+ from `e = 720` on. `m` is a staircase that steps down from 19 at `e = 1` to 1 from `e = 683` on.
749
+ The 20 of `NAME_PREMIUM_START` would apply only at `e = 0`, where the name has not lapsed. The re-claim is a
664
750
  **fresh basis**: prior `viaFill` immunity is void (immunity protects a *paid* basis; an unpaid
665
751
  lease is an abandoned one), and any still-open offer on the name is voided with its lock freed.
666
752
  - **Guards:** `nxfer`/`nset` on a lapsed lease are no-ops. A name **offer** is a no-op unless the
@@ -668,17 +754,19 @@ From height **32 000** every name is a **lease**:
668
754
  never hit a mid-window lapse; the alternative (a no-op'd CSD fill whose payment already
669
755
  confirmed to the seller) would be a fund-loss shape, so it is made unrepresentable. Offers
670
756
  anchored before v1.5 are exempt (their windows all end long before any grandfathered lease).
671
- - **State:** at v1.5+ tips `names[x]` carries `paidThroughEpoch` (and `expired: true` once
672
- lapsed; the record is kept for history until re-claimed). Pre-v1.5 canonical hashes are
757
+ - **State:** at v1.5+ tips every name except a pending reservation (§28) carries `paidThroughEpoch` (and
758
+ `expired: true` once lapsed at the tip's epoch, §5; the record is kept for history until re-claimed). Pre-v1.5 canonical hashes are
673
759
  unchanged: the fields exist only at v1.5+ tips.
674
760
 
675
761
  ## 18. `tmeta`: issuer token metadata via the content layer (v1.5)
676
762
 
677
763
  `{v:1,t:"tmeta",ticker,hash}`: **issuer-only**, last write wins, no fee beyond the anchor.
678
- `hash` is a csd-swarm Content Convention v1 hash (0x + 64 hex) pointing at the token's
679
- `{logo, description, links}` document: self-certifying content, so the record stays tiny
680
- (the 512-byte `uri` cap is untouched) and the metadata inherits the swarm's verify-on-read
681
- property. State: `tokens[t].tmeta`. Records before v1.5 are no-ops.
764
+ `hash` is a CSD Content Convention v1 hash (0x + 64 lowercase hex, §3; `payloadHash` in csd-codec) pointing at
765
+ the token's `{logo, description, links}` document: self-certifying content, so the record stays tiny
766
+ (the 512-byte `uri` cap is untouched) and any copy of the document can be checked against the hash
767
+ on read (`verifyContentBytes` in csd-codec). The csd-swarm content service this section was written
768
+ for is retired; the convention names no host for the document. State: `tokens[t].tmeta`. Records
769
+ before v1.5 are no-ops.
682
770
 
683
771
  ---
684
772
 
@@ -690,7 +778,8 @@ property. State: `tokens[t].tmeta`. Records before v1.5 are no-ops.
690
778
 
691
779
  - **Fee bump.** The taker fee becomes `FEE_BPS_V16 = 150` (1.5%, `ceil`) instead of `FEE_BPS = 100` (1%).
692
780
  The rate is **captured per-offer at creation height** into `offers[id].feeBps` (a bare-int canonical field,
693
- §5.1-A3): an offer anchored ≥ 33 600 carries `feeBps = 150`, an earlier one keeps `100`. Every fill of that
781
+ §5.1-A3): an offer anchored ≥ 33 600 carries `feeBps = 150`, one anchored in [29 960, 33 600) carries `100`, and one
782
+ anchored below 29 960 (v1.1) carries `0` and owes no trade fee (§10). Every fill of that
694
783
  offer (whole, partial, token-priced) uses the offer's own `feeBps`, so pre-v1.6 offers are byte-identical
695
784
  forever. A third-party resolver MUST select the fee by **offer-creation height**, not by fill height.
696
785
  - **Maker rebate (whole CSD-priced fills only).** On a whole fill of a **resting-liquidity** CSD-priced offer,
@@ -725,7 +814,9 @@ the 0.05 CSD attest fee, never a payment.
725
814
  - **Claim** = an `Attest` on the offer with **`score = SCORE_CLAIM = 50`** (∉ {fill 100, cancel 0}, so it is an
726
815
  inert no-op below V17, non-retroactive). It grants the attester an **exclusive hold** of the offer for
727
816
  `CLAIM_WINDOW_BLOCKS = 15` blocks: on grant the resolver records `offers[id].claimedBy = attester` and
728
- `offers[id].claimUntilHeight = grantHeight + 15` (both canonical fields, §5.1-A3, present only while claimed).
817
+ `offers[id].claimUntilHeight = grantHeight + 15` (both canonical fields, §5.1-A3, written at each grant and kept
818
+ after the hold ends and after the offer closes: a hold's end is read from `claimUntilHeight`, not from the fields'
819
+ absence).
729
820
  - **Fill gate.** A `SCORE_FILL` fill on an **untaken** (`taker === undefined`) CSD-priced offer at height ≥ V17
730
821
  is valid **only if** the offer is currently held **and the filler is the holder**: `claimHeld(o, h) &&
731
822
  attester === o.claimedBy`, where `claimHeld(o, h) = (o.claimedBy !== undefined) && (h < o.claimUntilHeight)`
@@ -777,8 +868,8 @@ no-op that forfeits the treasury output.)
777
868
  - **Inert metadata.** `p` is a flat string→string map. It carries **no fee, no value, and is never a send
778
869
  target**: the address a name resolves to for payment stays in `nset` (`names[x].addr`). A resolver keeps
779
870
  no reserved keys; the app layer keeps send targets out of `p`.
780
- - **Owner-gated, last-write-wins.** Valid iff the proposer is the current name owner and the lease is not
781
- lapsed (§17). The new `p` **replaces** the prior profile; an **empty `p` (`{}`) clears it**.
871
+ - **Owner-gated, last-write-wins.** Valid iff the proposer is the current name owner, the lease is not
872
+ lapsed (§17) and the name is not a pending reservation (§28). The new `p` **replaces** the prior profile; an **empty `p` (`{}`) clears it**.
782
873
  - **Cleared on every ownership change**: `nxfer`, a name `fill`, and a lapsed-premium re-claim all clear
783
874
  `profile` exactly as they clear `addr`.
784
875
  - **Shape limits (deterministic):** keys match `PKEY = ^[a-z0-9](?:[a-z0-9.-]{0,30}[a-z0-9])?$` (ASCII only,
@@ -856,9 +947,11 @@ The §24 lifetime cap proved to be an infrastructure symptom, not a market need,
856
947
  - **Anchor in [40 100, 41 300):** the §24 rules apply to that offer/bid FOREVER (creation gate at its
857
948
  anchor, capped `effExpiry` in every later sweep). Era membership is fixed by the anchor, so every
858
949
  replayer ages the same record identically regardless of when it replays.
859
- - **Anchor < 40 100:** raw `expires_epoch` binds (pre-V21 history, unchanged).
860
- - **Client closed form:** for anchor ≥ V22, `offerExpiryHeight = (expires_epoch+1)·30`; for the [V21, V22)
861
- era use the §24 formula; below V21 use the raw form.
950
+ - **Anchor < 40 100:** no creation gate (the record predates it), but every sweep at a height ≥ V21 reads it with the
951
+ capped `effExpiry` of §24, so over-cap inventory from before V21 expires at the first such sweep past its cap; a
952
+ sweep below V21 reads the raw `expires_epoch`, so every pre-V21 state is unchanged.
953
+ - **Client closed form:** for anchor ≥ V22, `offerExpiryHeight = (expires_epoch+1)·30`; for every anchor below V22,
954
+ `min((expires_epoch+1)·30, max(40 100, (epochOf(anchor)+MAX_OFFER_EPOCHS+1)·30))` (`offerExpiryHeightOf`).
862
955
  - **Adoption note:** a relaxation. A v2.1-only replayer rejects (no-ops) a long-dated offer the chain
863
956
  accepts, so its book diverges from the canonical one from the first over-cap anchor onward. Every
864
957
  replayer must run the v2.2 core before the tip crosses 41 300 (already long past; stated for the record).
@@ -934,16 +1027,21 @@ the settled winner ever pays.
934
1027
  is rejected at/after v2.5 (`v2.5: registration requires a commit-reveal (salt)`): an unsealed
935
1028
  registration could not be finalized.
936
1029
  - **Reveal (`name` record, height ≥ 46 440):** carries NO registration fee. Creates a PENDING reservation,
937
- materialized in canonical state as the name with `pending: true` and
938
- `finalizeBy = effHeight + 8 + 20` (`REG_COMMIT_MAX_BLOCKS + REG_FINALIZE_GRACE_BLOCKS`).
1030
+ materialized in canonical state (at v2.5+ tips) as exactly `{name, owner, claimId, height, effectiveHeight, locked,
1031
+ pending: true, finalizeBy}`, with `finalizeBy = effHeight + 8 + 20` (`REG_COMMIT_MAX_BLOCKS + REG_FINALIZE_GRACE_BLOCKS`).
1032
+ It holds no lease, so it carries no `paidThroughEpoch` and no `expired`, and it carries no `addr`, `viaFill` or
1033
+ `profile`.
1034
+ - **While pending** the reservation gives its owner only the right to finalize it: `nxfer`, `nset`, `nprofile` and a
1035
+ name `offer` by the owner, and `nrenew` by anyone, are no-ops on it (`NAME_PENDING`). Only `nfinalize`, a displacing
1036
+ reveal (below) and the expiry sweep act on a reservation.
939
1037
  - **Contest while pending:** a rival reveal with a strictly earlier `(effHeight, pos, id)` (numeric on
940
- `effHeight` and `pos`, ordinal code-unit on `id`; earliest wins) DISPLACES the reservation; the displaced party has lost only its
1038
+ `effHeight` and `pos`, ordinal code-unit on `id`; `pos` and `id` the reveal's own, §9; earliest wins) DISPLACES the reservation; the displaced party has lost only its
941
1039
  ~0.25 CSD anchor. A FINALIZED name can never be displaced: any window-valid challenger has an
942
1040
  `effHeight` within 8 blocks of the current height, which is strictly later than a finalized name's
943
1041
  (its freeze has passed). Names owned `viaFill` are likewise never displaced.
944
1042
  - **Per-address cap:** at most `MAX_PENDING_REG = 3` concurrent un-finalized reservations per owner
945
1043
  (expired ones and a re-reveal of the same name do not count); excess reveals are no-ops.
946
- - **Finalize (`nfinalize` record):** `{v:1, t:"nfinalize", name, salt}`. Valid iff ALL of: the name is
1044
+ - **Finalize (`nfinalize` record):** `{v:1, t:"nfinalize", name, salt}`, `salt` in the form of §9. Valid iff ALL of: the name is
947
1045
  pending and owned by the sender; `salt` re-derives the SAME commit that anchored the reservation
948
1046
  (`sha256` per §9, binding name + salt + owner, and the commit's height must equal the reservation's
949
1047
  `effHeight`); the freeze has passed (`ev.height > effHeight + 8`); the reservation has not expired
@@ -951,9 +1049,10 @@ the settled winner ever pays.
951
1049
  (§27, priced at the FINALIZE height). On success the `pending`/`finalizeBy` keys become ABSENT, the
952
1050
  lease starts (`paidThroughEpoch = epochOf(ev.height) + NAME_TERM_EPOCHS`), and the name is NOT
953
1051
  `viaFill`.
954
- - **Reservation expiry (lazy):** past `finalizeBy` an un-finalized reservation is swept exactly like a
955
- lapsed lease (at each event height and at the tip+1 closing sweep): the name record is DELETED and the
956
- name reopens. The would-be winner has lost only anchors, never the registration fee.
1052
+ - **Reservation expiry (lazy):** past `finalizeBy` an un-finalized reservation is deleted by the expiry sweep of §5
1053
+ (before each event above `finalizeBy`, and at the closing sweep at `tipHeight + 1`, so it is gone from the state at
1054
+ a tip equal to `finalizeBy`, although an `nfinalize` mined at that height still applies), and the name reopens. The
1055
+ would-be winner has lost only anchors, never the registration fee.
957
1056
  - **Client timing rule** (`FINALIZE_TIP_MARGIN = 2`, client-side only): sign the finalize at
958
1057
  `effHeight + 8 + 2` or later so one reorg cannot un-freeze the contest under a fee-bearing tx. The
959
1058
  20-block grace exists so a slow inclusion still lands before `finalizeBy`.
@@ -978,12 +1077,15 @@ decaying premium (up to hundreds of CSD).
978
1077
  record in `names` is left untouched (it is the premium basis; an abandoned reservation can never
979
1078
  bypass the premium). Below v2.6, recapture stays pay-now at reveal (§17, byte-identical).
980
1079
  - **Same windows and contest:** reveal window and freeze are `REG_COMMIT_MAX_BLOCKS = 8`;
981
- `finalizeBy = effHeight + 8 + 20`; lowest `(effHeight, pos, id)` displaces among reservations; its own
1080
+ `finalizeBy = effHeight + 8 + 20`; lowest `(effHeight, pos, id)` (the reveal's own `pos` and `id`) displaces among reservations; its own
982
1081
  `MAX_PENDING_REG = 3` per-address cap; overdue reservations are lazily swept.
983
1082
  - **Finalize:** the same `nfinalize` record, salt-bound to the recapture commit. The winner pays the §17
984
1083
  decaying premium priced at the FINALIZE height (slightly more decayed than at reveal: rounding favors
985
1084
  the payer). On success the name becomes a normal fresh lease under the new owner, NOT `viaFill`
986
- (displacement-immune by the same freeze arithmetic as §28).
1085
+ (displacement-immune by the same freeze arithmetic as §28). The new record keeps the reveal's anchor: `claimId` is
1086
+ the reveal's transaction id, `height` the reveal's height and `effectiveHeight` its commit's height (the finalize's
1087
+ own id and height are not recorded), and `paidThroughEpoch = epochOf(finalize height) + NAME_TERM_EPOCHS`; it
1088
+ carries no `addr` or `profile`, and `locked` is false.
987
1089
  - **Replayer note:** because the reservation map is internal, pre-v2.6 canonical hashes are untouched,
988
1090
  but a third-party resolver MUST still replicate the map (reveal, displacement, expiry) to agree on
989
1091
  which later `nfinalize` succeeds. The map is defined by this section plus the reference resolver and
@@ -1049,15 +1151,16 @@ gate a parsed fclaim is inert (nfinalize precedent, §28).
1049
1151
  stays at the 0.05 attest floor; only the claim rises to the 0.25 propose floor.
1050
1152
 
1051
1153
  **Grant (the propose handler, at height `h >= V28_HEIGHT`).** A well-formed fclaim grants a hold iff, in order:
1052
- the referenced offer exists AND is `open` AND untaken (`!taker`) AND CSD-priced; `E <= effExpiry(offer, h)`
1154
+ `E` is at most 2^53 − 1 (§33.4); the referenced offer exists AND is `open` AND untaken (`!taker`) AND CSD-priced; `E <= effExpiry(offer, h)`
1053
1155
  (§24 / §25, so the hold never outlives the offer); `E <= epochOf(h) + FCLAIM_MAX_EPOCH_AHEAD` (`= 2`, anti-squat,
1054
1156
  bounding a hold to `EPOCH_LEN*(2 + 1) - 1 = 89` blocks); `epochOf(h) <= E` (lower bound); the offer has no live
1055
1157
  hold (`!claimHeld`, unifying legacy and fclaim holds so one offer is never double-held); the same-offer cooldown
1056
1158
  has elapsed (`h >= o.claimUntilHeight + grace + CLAIM_COOLDOWN_BLOCKS` for the last holder, where `grace` is the
1057
1159
  prior hold's era grace per §20 / §23, i.e. 0 for a prior fclaim hold and `CLAIM_FILL_GRACE_BLOCKS` for a prior
1058
1160
  legacy hold; the cooldown runs from the END of the prior hold, so a straddling legacy hold and a fresh fclaim
1059
- never disagree); and the proposer holds fewer than `MAX_ACTIVE_CLAIMS` (`= 3`) live holds. This clause order is
1060
- normative (the from-spec oracle emits deny reasons in this order). On grant the resolver records `claimedBy = proposer`, `claimUntilHeight = (E + 1)*EPOCH_LEN`, and
1161
+ never disagree); and the proposer holds fewer than `MAX_ACTIVE_CLAIMS` (`= 3`) live holds. The grant is the
1162
+ conjunction of these clauses, so their order decides only the reason code of a denial: the code of the first clause
1163
+ broken (§40.1). The Python reference checks them in this order and writes no codes. On grant the resolver records `claimedBy = proposer`, `claimUntilHeight = (E + 1)*EPOCH_LEN`, and
1061
1164
  `claimTxid = fclaimTxid`.
1062
1165
 
1063
1166
  **Last-write-wins (fund-safety).** All three fields are last-write-wins: a later grant on the same offer (after
@@ -1162,10 +1265,18 @@ so a double-fed transaction (an overlapping scanner page delivered verbatim) app
1162
1265
  partial-fill path that double-credits `paid` / `delivered`. A transaction has ONE identity: a `Propose`'s
1163
1266
  `id`, an `Attest`'s `txid`. At an event height `>= V29_HEIGHT` the FIRST occurrence in consensus order
1164
1267
  (§3: height, propose-before-attest, pos, ordinal id/txid) is kept and every later occurrence of the same
1165
- identity is dropped BEFORE apply. Below the gate nothing is dropped. A duplicate pair shares one txid and
1166
- therefore one mined block, so both copies always land on the same side of the gate; there is no straddle
1167
- case. (The cairnx service also de-duplicates its attestation pull at scan time; that is a transport-side
1168
- defensive measure, deliberately NOT part of this convention. Only the `resolve()` drop is normative.)
1268
+ identity is dropped BEFORE apply. Below the gate nothing is dropped. Two copies of one event that a feed
1269
+ delivers twice share one txid, height and position, so they land on the same side of the gate. A
1270
+ transaction can also be mined again: coinbase txids are not unique on this chain, so a spent coin can be
1271
+ created again and the same spending transaction mined in a later block. Those copies sit in two blocks,
1272
+ possibly on both sides of the gate, and `resolve()` fed both drops the later copy only when both are at or
1273
+ above the gate. §33 keeps the first occurrence, so a feed built by its rule holds neither kind of duplicate;
1274
+ the drop above stays the rule for a feed that is not built by it. A list holding one transaction id at two places (a
1275
+ later height, or another position in the same block) with the first copy below the gate is not a list §33 produces
1276
+ (§33.2), and no level of §38 covers `resolve()` over it; there the two reference implementations differ: from V14, an
1277
+ offer among its seller's `ocancel` targets, fed again after that `ocancel` in its block, stays open past its expiry in
1278
+ cairnx-core and expires in the Python reference. Two copies at one height and position below the gate both apply in
1279
+ both, as `cases-v29.json` pins.
1169
1280
 
1170
1281
  **M5: the concurrent-hold cap counts only OPEN holds (relaxation).** §20/§31 cap an address at
1171
1282
  `MAX_ACTIVE_CLAIMS` (= 3) live holds, counted as `claimedBy === who && claimHeld(o, h)`. A FILLED offer
@@ -1191,3 +1302,678 @@ divergence height is pinned by the fork-lens vector set (`cases-v29.json`).
1191
1302
  before the tip crosses 88 000, never "publish and hope". The `replay-hashes.json` V29 entry is pinned
1192
1303
  only POST-crossing from the live chain (see CONSENSUS_CHANGES.md); a pre-crossing V29 hash would be an
1193
1304
  invented pin and is forbidden.
1305
+
1306
+ ---
1307
+
1308
+ # CairnX chain input (no gate)
1309
+
1310
+ ## 33. From a block to events
1311
+
1312
+ `resolve()` (§3, §5) replays a list of events. This section is the rule that makes that list from the chain's
1313
+ blocks; two readers that apply it to the same blocks feed `resolve()` the same events. It has no activation gate:
1314
+ it is the input form the reference service has always replayed (§33.2), and where other readers used other forms
1315
+ (an expiry above 2^53 - 1, a `uri` holding U+0000), `resolve()` derives the same state from both forms (§33.4).
1316
+
1317
+ The rule has two parameters: a domain D and an activation height A. CairnX uses D = `cairnx:v1` and A = 29 860
1318
+ (`DOMAIN` and `ACTIVATION_HEIGHT`, together `CAIRNX_EVENT_RULE`). D is a non-empty, well-formed string holding
1319
+ neither U+0000 nor U+0001; A is an integer >= 0. Another application may apply the rule with its own D and A.
1320
+
1321
+ ### 33.1 Membership
1322
+
1323
+ A transaction at height h and position p (its index in the block; the coinbase is at 0) is an event when h >= A and
1324
+
1325
+ - it is a `Propose` whose domain equals D, code unit for code unit, or
1326
+ - it is an `Attest` whose proposal id is the id of a `Propose` event of this rule at a height <= h. A `Propose`
1327
+ event in the same block counts at any position, before or after the `Attest`: the node applies a block's
1328
+ proposals before its attestations (C5).
1329
+
1330
+ Nothing below A is an event, and nothing below A is read: an `Attest` at or above A on a `Propose` mined below A is
1331
+ not an event. A transaction without an app payload is not an event. The coinbase is never an event: consensus
1332
+ refuses a block whose first transaction is not the coinbase or whose coinbase carries an app payload, so a list
1333
+ with an app payload at position 0 is not a block of the chain, and a reader refuses it.
1334
+
1335
+ A reader may apply the rule to a sparse block: a list in strictly increasing position order, each transaction at
1336
+ its true position, that holds every transaction of the block that carries an app payload. A complete block is one
1337
+ such list. The rule cannot see whether a list is complete; establishing that is the reader's. A complete block
1338
+ whose transactions hash to the merkle root of a header the reader verified establishes it; a feed (a node's events
1339
+ route, a recorded fixture) establishes it only on the feed's word.
1340
+
1341
+ ### 33.2 First occurrence
1342
+
1343
+ A transaction id is one event, at the lowest height at or above A at which the chain holds it. A block holds a
1344
+ transaction id at most once (consensus refuses a block that repeats one), so a reader refuses a list that repeats
1345
+ one. A transaction id can still sit in two blocks: coinbase transaction ids are not unique on this chain, so a
1346
+ spent coin can be created again and the same spending transaction mined in a later block. Its later copies are not
1347
+ events. Occurrences below A are never read, so a transaction mined below A and again at or above A is an event at
1348
+ its first height at or above A, when it is a member there. This fixes the input form the reference service has
1349
+ always replayed (csd-indexer keeps the first occurrence of a transaction id at every height, and the service reads
1350
+ that feed), so a reader that feeds `resolve()` every copy of a re-mined transaction can differ from the reference
1351
+ when a copy lies below V29, where §32's M4 drop does not apply.
1352
+
1353
+ A reader that applies the rule a block at a time keeps two sets, derived from the events it holds and rolled back
1354
+ with them on a reorganisation: the ids of all its events (a `Propose`'s id, an `Attest`'s transaction id) and the
1355
+ ids of the `Propose` events among them.
1356
+
1357
+ ### 33.3 Order
1358
+
1359
+ A block's events are listed in apply order: its `Propose` events by position, then its `Attest` events by
1360
+ position; blocks follow by height. This is the order of §3.
1361
+ The reference comparator is `applyOrder` (with `eventId`, the id it compares last), the function `resolve()` sorts with.
1362
+
1363
+ ### 33.4 Field forms
1364
+
1365
+ Each event is a `ProposeEvent` or an `AttestEvent` (`src/types.ts`). Transaction ids, hashes and addresses are
1366
+ written `0x` and lowercase hex: 64 digits for 32 bytes, 40 for 20 bytes. An output's address is its 20-byte
1367
+ `script_pubkey`. The fields are taken from the transaction as decoded from its consensus bytes or its node JSON,
1368
+ with u64 values exact. In JavaScript a u64 input (an expiry, an output value) is a bigint in [0, 2^64), or a number
1369
+ that is an integer in [0, 2^53]: 2^53 is accepted as a number because it is the rule's own form of a clamped expiry,
1370
+ and a number above 2^53 is refused, because such a double no longer identifies one u64. The rule does not check
1371
+ again what the node checked (fee floors, `uri` length, expiry at creation).
1372
+
1373
+ | Field | Value |
1374
+ |---|---|
1375
+ | `kind` | `"propose"` or `"attest"` |
1376
+ | `id` (Propose), `txid` (Attest) | the transaction id |
1377
+ | `proposer`, `attester` | the author (§33.5) |
1378
+ | `uri` | the consensus text with each U+0000 written as U+0001, the form csd-indexer keeps from 0.3.8 on. JSON admits neither character unescaped, so a `uri` holding either is no record in both forms |
1379
+ | `payloadHash`, `proposalId` | the consensus 32 bytes |
1380
+ | `expiresEpoch` | the consensus u64 when it is at most 2^53 - 1, otherwise 2^53 (9007199254740992). `resolve()` reads it only for offers, bids and fclaims, and refuses each of those above 2^53 - 1 |
1381
+ | `score`, `confidence` | the consensus u32 values |
1382
+ | `height`, `pos` | the block height; the position in the block |
1383
+ | `paidTo` | for each address paid by an output whose value is at most 2^53 - 1, the sum of those outputs' values as a decimal string (an output of value 0 lists its address with `"0"`); an output above 2^53 - 1 is left out, since the total supply can exceed 2^53 - 1 |
1384
+
1385
+ ### 33.5 The author
1386
+
1387
+ The author of an event (`proposer`, `attester`) is the owner of the output that the transaction's first input
1388
+ spends: that output's `script_pubkey`. The node accepts the first input only when hash160 of the public key in its
1389
+ signature script equals that `script_pubkey` (C3), so for a mined transaction the two are one address. The
1390
+ transaction id does not commit the signature script, so a copy of a mined transaction can carry another key's
1391
+ valid signature and still match its merkle root. The rule therefore takes the author as an input the reader binds:
1392
+ the spent output is read from its source transaction after that transaction's id is recomputed, and csd-crypto
1393
+ `authorOf(tx, scriptPubkey)` returns the owner only when the first input's signature is the owner's. A copy for
1394
+ which it returns null is a damaged copy, to be read again from another source, never an event of another author. A
1395
+ reader that cannot bind the author of a member has no events for that block; it never leaves the event out.
1396
+
1397
+ ### 33.6 The byte form of an event list
1398
+
1399
+ The bytes of an event list are csd-codec `canonicalJson` of the array of events in the order of §33.3 (keys in
1400
+ code-unit order at every depth, §5.1). No event key and no `paidTo` key is an array index, so §5.1 A2 does not
1401
+ arise.
1402
+
1403
+ ### 33.7 Reference functions and vectors
1404
+
1405
+ cairnx-core exports the rule as `eventOfTx`, `blockMembers`, `blockEvents` and `CAIRNX_EVENT_RULE`;
1406
+ `conformance/cairnx_ref.py` implements the same three functions independently.
1407
+
1408
+ - `eventOfTx(t, height, author, rule?)` maps one transaction (`{pos, txid, tx: {app, outputs}}`) to its event, or to
1409
+ null when it carries no app payload, lies below A, or is a `Propose` in another domain. It does not decide `Attest`
1410
+ membership, which needs the block: a caller that reads single transactions (a wallet proving one fill, a scanner
1411
+ reading a feed that joins attestations to their proposals) decides it itself. An `Attest` on a proposal that is
1412
+ not an event changes no state: `resolve()` ignores it.
1413
+ - `blockMembers(height, txs, sofar, rule?)` returns the members of one block (§33.1, §33.2) in position order, so a
1414
+ reader binds authors for those alone; `sofar` holds the two sets of §33.2. `txs` is a list as §33.1 describes.
1415
+ - `blockEvents(height, txs, sofar, authors, rule?)` returns the block's events in the order of §33.3, with
1416
+ `authors[i]` the author of the i-th member. It selects the members again, so a list of authors one short is
1417
+ refused.
1418
+
1419
+ Each refuses (throws; `ValueError` in Python) input that is not a block of the chain or not in the forms of
1420
+ §33.4: positions that are not integers >= 0 in strictly increasing order, a transaction id repeated in a block, an
1421
+ app payload at position 0, a field outside its consensus type (hex of the wrong length, an integer out of range,
1422
+ text that is not well-formed), a member without an author, and a rule whose domain or activation height is not
1423
+ in the form above. Hex input may carry a `0x` prefix or none, with its digits in either case. An integer field (a
1424
+ height, the activation height, a position, a score, a confidence) may come in any JSON spelling of its value (`1`,
1425
+ `1.0`, `1e0`); a boolean is not an integer.
1426
+ `eventOfTx` checks the height, position, transaction id and app type of any transaction; of one below A it reads
1427
+ nothing more, and it checks the remaining fields and the author only of an event. `blockMembers` checks the
1428
+ position, transaction id and app type of every listed transaction, the domain of every `Propose` and the proposal
1429
+ id of every `Attest`; `blockEvents` checks in addition what `eventOfTx` checks of each member. Neither reads
1430
+ anything of a block below A.
1431
+
1432
+ `test/vectors/events.json` holds the language-neutral vectors, `{format: 1, rule, tx, blocks}`, one case per line.
1433
+ A `tx` case gives `input` (`txid`, `height`, `pos`, `app`, `outputs`, field names as in csd-codec's `Tx`, u64 values
1434
+ as decimal strings), `author`, and `expect`: the event, null, or `"error"`. A `blocks` case gives a sequence of
1435
+ blocks (`{height, txs}`), the authors by transaction id, and `expect`: the members' positions per block and the
1436
+ events of the whole sequence, or `{"error": i}` with i the first block refused. The two sets carry across a case's
1437
+ blocks, and a member whose author is not listed is given null. A conformant reader reproduces every case, each
1438
+ event list as the bytes of §33.6.
1439
+
1440
+ Feeds are not this rule's output. csd-indexer's chain-order feed of a domain's attestations includes attestations
1441
+ on proposals below A, which `resolve()` ignores; a node's events route can list every copy of a re-mined
1442
+ transaction, and §32's M4 drop removes only the copies at heights at or above V29.
1443
+
1444
+ ---
1445
+
1446
+ # Comparing replicas (no gate)
1447
+
1448
+ ## 34. State hash and events hash
1449
+
1450
+ Two replicas that replay the same chain compare two hashes at one block: the events hash commits what they read, the
1451
+ state hash what they derived. Neither enters a record or the canonical state, so defining them moves no state; both
1452
+ are fixed byte for byte here so that every replica computes them alike.
1453
+
1454
+ ### 34.1 The state hash
1455
+
1456
+ The state hash of a resolver state is sha256 of the UTF-8 bytes of its canonical state (§5, §5.1, with the
1457
+ integer-key order of A2), written `0x` and 64 lowercase hex digits. Besides the seven keys of §5's surface, a
1458
+ `resolve()` result carries three diagnostic fields that the canonical state leaves out: `events` (the applied log),
1459
+ `recaptures` (§29) and `fclaims` (§31); the state hash of a complete result is the hash of its surface alone. At
1460
+ height h it is the state hash of `resolve()` over the events at heights <= h with tip h;
1461
+ `test/vectors/replay-hashes.json` pins that digest, without the `0x`.
1462
+
1463
+ ### 34.2 The events hash
1464
+
1465
+ The events hash runs over the events of §33 block by block. For a block at height h that holds at least one event:
1466
+
1467
+ ```
1468
+ b = sha256( h as 8 bytes big endian || row_1 || ... || row_n )
1469
+ row_i = position as 4 bytes big endian || transaction id (32 bytes) || author (20 bytes)
1470
+ ```
1471
+
1472
+ with one row per event of the block, in ascending position. The transaction id is a `Propose`'s `id` or an
1473
+ `Attest`'s `txid`, the author its `proposer` or `attester`. The order is position order, not the apply order of
1474
+ §33.3, which lists `Propose` events first; positions within a block are distinct. The running value e is 32 zero
1475
+ bytes before the first block at or above A, and each block that holds an event, in ascending height, replaces it:
1476
+
1477
+ ```
1478
+ e = sha256( e_prev || b )
1479
+ ```
1480
+
1481
+ A block without events leaves e as it is. The events hash at height h is e after the last block at or below h that
1482
+ holds an event, written `0x` and 64 lowercase hex digits.
1483
+
1484
+ Height and position are in the hash because the resolver compares positions of records in different blocks (the
1485
+ name contests of §9 and §28). The transaction id commits every other field of the transaction, and the author, which
1486
+ it does not commit (§33.5), is in the row, so no JSON form, number form or text storage enters the hash.
1487
+
1488
+ ### 34.3 Comparing two replicas
1489
+
1490
+ Two replicas compare (height, block hash, events hash, state hash) at one height. The comparison means something only
1491
+ at a height both treat as final (§38 names the depth): near the tip two honest replicas can hold different blocks
1492
+ for a while.
1493
+
1494
+ - Another block hash at the height: the replicas follow different branches. Wait and compare again; this is a
1495
+ branch difference, never a divergence.
1496
+ - The same block hash, another events hash: the replicas read different events from the same blocks, so their record
1497
+ sources differ (a source left out or added a transaction, or recorded another author, height or position).
1498
+ - The same events hash, another state hash: the replicas read the same transactions at the same places with the same
1499
+ authors and apply different rules to them: the resolver (§3 to §32), or the field forms of §33.4, which the events
1500
+ hash does not see.
1501
+
1502
+ The running value carries every earlier block, so the first block whose events differ lies after the last height at
1503
+ which the events hashes agree.
1504
+
1505
+ ### 34.4 Reference functions and vectors
1506
+
1507
+ cairnx-core exports `stateHash`, `eventsHashStep`, `eventsHash` and `EVENTS_HASH_START` (the 32 zero bytes);
1508
+ `conformance/cairnx_ref.py` implements them independently.
1509
+
1510
+ - `stateHash(state)` is the state hash of a `resolve()` result.
1511
+ - `eventsHashStep(prev, height, events)` is e after one block from the value `prev`, with `events` the block's
1512
+ events in any order; for no events it is `prev`.
1513
+ - `eventsHash(events)` is e over a list from the start value. The list is in the order of §33.3 or in an order that
1514
+ differs from it only within a block, so each height forms one run. Unlike `resolve()`, it does not sort across
1515
+ heights: a list in another order is sorted by height first.
1516
+
1517
+ Values, transaction ids and authors are `0x` and lowercase hex, the forms of §33.4; a height is an integer in
1518
+ [0, 2^53 - 1], a position an integer in [0, 2^32 - 1], either in any JSON spelling of its value (`100000.0` and `1e5`
1519
+ are 100000); a boolean is not an integer. Each function refuses (throws; `ValueError` in Python) a
1520
+ previous value, transaction id or author in another form (upper case or without `0x` included), a height or position
1521
+ out of its range, an event whose kind is neither `propose` nor `attest`, an event whose height is not the step's, and
1522
+ a position repeated in a block; `eventsHash` refuses a height below the one before it. `eventsHashStep` sees no
1523
+ earlier height, so a caller that steps block by block keeps the blocks in order. Neither reads any other field.
1524
+
1525
+ `test/vectors/hashes.json` (`conformance/gen-hashes-vectors.mjs`) holds the vectors, `{format: 1, start, cases,
1526
+ corpus}`, one case per line. A case gives `blocks` (`{height, events}`, each event with the five fields above), may
1527
+ give `prev`, and gives `expect`: `steps`, `eventsHashStep` applied to the blocks in turn from `prev` or the start
1528
+ value, as the value or `{"error": i}` with i the first block refused; and, without `prev`, `list`, `eventsHash` over
1529
+ the blocks' events in turn, as the value or `"error"`. `corpus` gives both hashes over
1530
+ `test/vectors/replay-corpus.json` at each height of `replay-hashes.json`, the events at heights <= h in a stable sort
1531
+ by height.
1532
+
1533
+ ---
1534
+
1535
+ # CairnX for other applications (no gate)
1536
+
1537
+ ## 35. Other applications
1538
+
1539
+ This section and §36 bind an application that is not CairnX and reads or writes on the same chain. Neither has an
1540
+ activation gate: they state what the reference already does and reserve names for later, so they move no state.
1541
+
1542
+ ### 35.1 Record types under `cairnx:v1` are reserved
1543
+
1544
+ Every record type under `cairnx:v1` belongs to this convention. A record whose `t` this version does not define is a
1545
+ no-op today (§3), and a later gate may give that type a meaning; from the gate's height on, a record of that type is
1546
+ read by the new rule, whoever anchored it and for whatever purpose. A record of a defined type with a key its schema
1547
+ does not list is a no-op too (§5.1 A8). An application therefore must not anchor its own records under `cairnx:v1`,
1548
+ neither as a new type nor as extra keys on a defined one.
1549
+
1550
+ ### 35.2 An application's own domain
1551
+
1552
+ An application's own records go in its own domain, named `<app>:<major>`: `<app>` names the application and `<major>`
1553
+ is the major version of its record format. A domain is a string of the form §33 requires of D. Domains whose text
1554
+ begins with `cairnx`, `csd` or `cairn` are reserved to this convention and its maintainers; an application uses none
1555
+ of them.
1556
+
1557
+ A domain is a label and not an authority. Anyone can anchor a `Propose` under any domain, a reserved one included,
1558
+ and reserving a prefix gives no one control of it. An application decides which authors it accepts under its domain,
1559
+ with the author of §33.5.
1560
+
1561
+ The rule of §33 takes the domain and the activation height as parameters (`EventRule`; `CAIRNX_EVENT_RULE` is
1562
+ CairnX's), so an application reads its own domain with the same functions (`eventOfTx`, `blockMembers`,
1563
+ `blockEvents`) and its own D and A. `resolve()` reads only CairnX records; the meaning of an application's records is
1564
+ the application's to define.
1565
+
1566
+ ### 35.3 Data for readers of a name: the profile
1567
+
1568
+ Data an application publishes for the readers of a name (a site, a node address, a pointer to its own data) goes in
1569
+ the name's profile, the `nprofile` record of §22, under the keys of §36.
1570
+
1571
+ - A write replaces the whole map: the resolver stores the record's `p` as the profile, and `{}` clears it (§22). A
1572
+ writer therefore reads the current profile first and writes the merged map, with every key it did not set kept at
1573
+ its current value.
1574
+ - A reader ignores the profile of a name that is expired or pending. In the state of §5 these are a name with
1575
+ `expired: true` (its lease and grace have lapsed, §17) and a name with `pending: true` (a reservation of §28 not yet
1576
+ finalized; `resolve()` materializes it without a profile). An expired name keeps its last profile in state until the name is claimed again; that profile is
1577
+ history, not the word of a current owner.
1578
+
1579
+ Known limit: only the owner writes a profile (§22), and two writers for one owner (two applications, or two devices)
1580
+ that read the same profile and both write within one block interval lose one write: the later in apply order (§3)
1581
+ replaces the map, and the keys only the earlier write carried are gone. The convention has no per-key write; a writer
1582
+ that needs its write kept reads the profile again once its record is mined.
1583
+
1584
+ ### 35.4 Forward resolution: the address a name receives at
1585
+
1586
+ A payment to a name goes to its `addr` (set by `nset`, §9, §26), else to its owner, so a name receives before its owner
1587
+ sets an address. Read from `names` in the state of §5 at a tip:
1588
+
1589
+ | The name in `names` | Resolves to |
1590
+ |---|---|
1591
+ | held, with `addr` | `addr` (`via: "nset"`) |
1592
+ | held, without `addr` (not set, or cleared by an `nset` to the zero address from V23) | the owner (`via: "owner"`) |
1593
+ | held, with the zero address as `addr` (an `nset` to it below V23 stored it, §26) | the zero address (`via: "nset"`); a wallet refuses to pay it (§26) |
1594
+ | in grace (§17: past `paidThroughEpoch`, without `expired`) | as held |
1595
+ | with `expired: true` (§17) | the record's address, flagged `lapsed: true`; a sender refuses it |
1596
+ | with `pending: true` (§28) | nothing: a reservation confers no address |
1597
+ | absent | nothing |
1598
+
1599
+ A name an open offer locks (§9) resolves as held. A sale and an `nxfer` clear `addr`, so the new owner receives until
1600
+ it sets one. The profile is not read (§36.3). A reserved name (`RESERVED_NAMES`) is absent from `names`, since a record
1601
+ that claims it does not parse (§9), so it resolves to nothing. The name is looked up as `names` writes it: a reader
1602
+ lowercases its input, drops a `.csd` suffix and refuses a string that does not match `NAME_RE` before it asks. In
1603
+ JavaScript `names` is a plain object and `constructor` matches `NAME_RE`, so a reader tests for an own key: a bare index
1604
+ on an unregistered `constructor` reads `Object.prototype.constructor`.
1605
+
1606
+ cairnx-core exports the rule as `resolveNameIn(names, name)`, which answers `{name, addr, via, lapsed, owner}` or null,
1607
+ and `nameView(names, name)` for a reader that shows a name: its class (`held`, `pending`, `lapsed`, `free` when absent,
1608
+ `reserved`), its owner (the reserver of a pending name, the last owner of a lapsed one), its address and its profile (a
1609
+ held name's only, §35.3) and its `paidThroughEpoch`; null for a string that does not match `NAME_RE`.
1610
+ `test/vectors/forward.json` (`conformance/gen-forward-vectors.mjs`) holds the cases, one per line: the events, the tip,
1611
+ and for each name asked the answers of both functions over `resolve(events, tip).names`, written by hand. Neither
1612
+ function writes state, so this section has no gate.
1613
+
1614
+ ## 36. The profile-key registry
1615
+
1616
+ This is the registry of profile keys, the first version. The resolver validates keys by their form alone and keeps no
1617
+ list of them (§22), so the registry binds writers and readers, not replay.
1618
+
1619
+ ### 36.1 The caps
1620
+
1621
+ From `src/types.ts`; a record that breaks one is a no-op (§22).
1622
+
1623
+ | Cap | Constant | Value |
1624
+ |---|---|---|
1625
+ | keys in one profile | `PROFILE_MAX_KEYS` | 16 |
1626
+ | UTF-8 bytes of one value | `PROFILE_MAX_VALUE_BYTES` | 256 |
1627
+ | UTF-8 bytes of the whole record, its `uri` | `MAX_RECORD_BYTES` (the node's `uri` cap, C4) | 512 |
1628
+ | the form of a key | `PKEY` | `^[a-z0-9](?:[a-z0-9.-]{0,30}[a-z0-9])?$`: 1 to 32 characters, lowercase letters and digits, with dots and hyphens inside |
1629
+
1630
+ Each value is a string. The resolver accepts any well-formed string within the byte cap (§5.1 A7), the empty string
1631
+ included; the forms below are what a reader accepts as the value of a registered key.
1632
+
1633
+ ### 36.2 The keys
1634
+
1635
+ | Key | Value |
1636
+ |---|---|
1637
+ | `display`, `description`, `avatar`, `header`, `url`, `email`, `location`, `com.twitter`, `com.github`, `com.discord`, `org.telegram`, `com.linkedin`, `com.reddit` | the 13 keys the reference site's profile editor writes, registered as they are: a display name, a short text, an image URL (`avatar`, `header`, `https://` only), a link (`url`, below), an email address, a place, and six handles on the named services |
1638
+ | `url` | an `https://` link |
1639
+ | `contenthash` | a URI: `ipfs://<CIDv1>`, with nothing after the CID. Not ENS's binary encoding. A later revision of this registry may add `ipns://`; it is not valid now |
1640
+ | `csd.*` | reserved to this convention for keys about the chain itself; only the keys below are defined |
1641
+ | `csd.p2p` | a peer of the chain's own network: a libp2p multiaddr that ends with its peer id (`/p2p/<peer id>`) |
1642
+ | `csd.rpc` | an address through which a page reaches a node's API: an `https://` base URL without credentials, query or fragment, or the multiaddr of a gateway that carries that API, ending with the gateway's peer id |
1643
+ | an application's keys | under a reverse-DNS prefix of a domain the application controls, for example `org.example.app` for the application at `app.example.org`; the whole key matches `PKEY` |
1644
+
1645
+ The six service keys of the editor (`com.twitter` to `com.reddit`) are reverse-DNS names of domains this convention
1646
+ does not control. They are registered as the editor writes them and are the only such keys.
1647
+
1648
+ ### 36.3 Reader rules
1649
+
1650
+ - Accept only the schemes and forms stated in §36.2, and treat any other value of a registered key as absent.
1651
+ - `csd.p2p` and `csd.rpc`: never use an address that is loopback, link-local or private, whether it is written as an
1652
+ address or reached through a name that resolves to one. A multiaddr ends with a peer id, and a reader dials that
1653
+ peer only with its peer id checked.
1654
+ - An address that a name's profile publishes is that name owner's node. What is read through it is at most single
1655
+ records, each proven for inclusion with its author bound to the coin it spent (§33.5; the record proof of §37),
1656
+ never a complete history, and never what marks any name, that one or another, as verified.
1657
+ - A profile is never a send target (§22): the address a name pays to is `addr`, set by `nset`, else the owner (§35.4).
1658
+ - The profile of an expired or pending name is ignored (§35.3).
1659
+
1660
+ ### 36.4 The byte budget
1661
+
1662
+ For a 32-character name, each row is the record `nameProfile` builds, measured with `canonicalJson`, in UTF-8 bytes
1663
+ against `MAX_RECORD_BYTES`. `node scripts/profile-budget.mjs` in the csd-sdk repository prints every figure, and its
1664
+ test keeps this table equal to that output. The example values are of a realistic length: `contenthash` a CIDv1 in
1665
+ base32, 66 bytes; `csd.p2p` a DNS multiaddr with an Ed25519 peer id, 89 bytes; `csd.rpc` an https base URL, 24
1666
+ bytes, or a WebRTC gateway multiaddr with a certificate hash and a peer id, 158 bytes; each editor key 12 bytes.
1667
+
1668
+ | Profile | Keys | Record bytes | Left of 512 |
1669
+ |---|---|---|---|
1670
+ | empty | 0 | 71 | 441 |
1671
+ | `contenthash` | 1 | 153 | 359 |
1672
+ | `contenthash`, `csd.p2p` | 2 | 255 | 257 |
1673
+ | `contenthash`, `csd.p2p`, `csd.rpc` (https URL) | 3 | 292 | 220 |
1674
+ | `contenthash`, `csd.p2p`, `csd.rpc` (gateway multiaddr) | 3 | 426 | 86 |
1675
+ | 13 editor keys, `contenthash`, `csd.p2p` | 15 | 601 | 89 over: `nameProfile` refuses it |
1676
+
1677
+ The 13 editor keys and the three registered keys `contenthash`, `csd.p2p` and `csd.rpc` are 16 keys, the key cap
1678
+ exactly, yet the last row, with 15 of them and 12-byte values, is already over the byte cap. The byte cap binds
1679
+ before the key cap, so an application uses one key that points at its own data rather than one key per field.
1680
+
1681
+ ### 36.5 Adding a key
1682
+
1683
+ A key is added to the registry by a change to this file: a row in §36.2 with its value form, and its reader rules in
1684
+ §36.3 when it needs any. It needs no gate, since the resolver keeps no list of keys. A key under an application's own
1685
+ reverse-DNS prefix needs no registration.
1686
+
1687
+ ---
1688
+
1689
+ # What a result proves (no gate)
1690
+
1691
+ ## 37. The three levels
1692
+
1693
+ A result says which of three levels it is.
1694
+
1695
+ 1. Display. An answer read from someone's API. It is worth the trust placed in that API.
1696
+ 2. Record proof. One record was mined in a block under valid proof of work, and its author is the owner of the coin
1697
+ its first input spends (§33.5). It does not prove that the record is the latest for its name or token, and it
1698
+ decides nothing about a name whose state depends on records outside the name's own history (a fill that depends
1699
+ on the buyer's other claims or balance, a registration that depends on the registrant's other reservations).
1700
+ 3. Replica. `resolve()` over every event of §33. It is exact for names and tokens when its event list is complete;
1701
+ §33.1 states what establishes that. What it proves depends on its source:
1702
+ - blocks from one's own node: the trust is one's own node;
1703
+ - complete blocks checked against headers: a block cannot be thinned, because its transactions must hash to the
1704
+ merkle root of the header and each author is bound to the coin it spent; what remains to trust is that the
1705
+ header source serves the chain with the most work;
1706
+ - a record log fixed in a release, plus complete blocks above the height it ends at: below that height the trust
1707
+ is the release;
1708
+ - a feed: a node's events route, csd-indexer's feeds, or any other list of records. A feed is complete only on its
1709
+ word, so a replay fed from one gives display, or a record proof for each record it proves, and says so. From
1710
+ one's own node the events route is the node software's word, which a replica makes equal to the first source by
1711
+ a recount from blocks at the boundaries of §38.
1712
+
1713
+ ---
1714
+
1715
+ # Conformance and rule changes (no gate)
1716
+
1717
+ ## 38. Conformance
1718
+
1719
+ A replica conforms at three levels.
1720
+
1721
+ 1. The vectors: `test/vectors/cases.json`, `cases-v29.json`, `cases-rules.json` and `cases-convention.json` (replay, §5), `events.json`
1722
+ (§33.7) and `hashes.json` (§34.4). A conformant implementation reproduces every case byte for byte.
1723
+ 2. The pinned replay hashes: `test/vectors/replay-hashes.json`, the state hash (§34.1) of the live chain at each
1724
+ pinned height.
1725
+ 3. A running comparison: two replicas compare the tuple (height, block hash, events hash, state hash) of §34.3 at
1726
+ finalized epoch boundaries. An epoch is `EPOCH_LEN` = 30 blocks (csd-codec, re-exported by cairnx-core); a
1727
+ boundary is a height that is a multiple of `EPOCH_LEN`, and a finalized boundary is one that both replicas hold at
1728
+ least `FINAL_DEPTH` = 12 blocks below their tips (cairnx-core `FINAL_DEPTH`). The thresholds of §3 (3 and 6) are
1729
+ display conventions and are not this depth; neither is a bound on how deep a reorganisation can reach.
1730
+
1731
+ What a difference means is in §34.3. The operating rule: a difference is reported, never acted on automatically. A
1732
+ replica that credits value stops crediting only when a difference at one block hash persists over three consecutive
1733
+ boundaries and its own recount from complete blocks (§37) gives the same difference.
1734
+
1735
+ A form of the tuple recorded on chain is reserved under the reserved prefixes of §35.2 and is not defined by this
1736
+ version.
1737
+
1738
+ `test/vectors/codes.json` (§40.7) is not a level: the reason codes move no state. A replica that publishes codes
1739
+ reproduces it. `test/vectors/moves.json` (§41) is not a level: the token moves move no state. A replica that publishes
1740
+ moves reproduces it.
1741
+
1742
+ ## 39. Rule changes
1743
+
1744
+ - This specification is normative for the future. Pinned history stands: every height below a gate replays as it
1745
+ did, and the pinned replay hashes do not move. Behaviour changes only at a gate, an activation height in
1746
+ `src/types.ts`; a section without a gate, such as §33 to §41, moves no state.
1747
+ - `CONSENSUS_CHANGES.md` in the csd-sdk repository is the ledger of every change. Each gate after v2.9 also has its
1748
+ own file, `docs/gates/<gate>.md`, written from `docs/gates/TEMPLATE.md` and linked from its ledger entry. It
1749
+ states the motivation, the rule text, the class of the change (reject-more: an input the earlier rule applied
1750
+ becomes a no-op; accept-different: an input is applied where it was not, or applied otherwise), the height, the
1751
+ vectors that pin it, and a rollout table of every consumer with how its adoption is observed.
1752
+ `scripts/check-consensus-citations.mjs` checks the citations of the ledger and of every gate file, and that each
1753
+ gate file is linked from the ledger.
1754
+ - A published height never moves earlier. (The v2.4 to v2.7 heights were moved earlier once, on 2026-07-03, before
1755
+ this rule; see the note at the top of this file.)
1756
+ - Rule changes ride gates within `cairnx:v1`. A second domain is only for a deliberate restart of state: its records
1757
+ are not events of `cairnx:v1` (§33.1), so it starts from no tokens, no balances and no names.
1758
+
1759
+ ---
1760
+
1761
+ # Reason codes (no gate)
1762
+
1763
+ ## 40. Reason codes
1764
+
1765
+ Every entry of the applied log (§5) carries `code`, the rule that decided the record, beside its `note`. A record that
1766
+ does not parse is refused with a record code, which `explainRecord(uri, payloadHash)` returns and a record builder's
1767
+ `RecordError` carries. The log stays outside canonical state, so codes move no state, and a replica that writes no
1768
+ codes conforms at every level of §38.
1769
+
1770
+ ### 40.1 What a code is
1771
+
1772
+ - A code names one rule. A rule that several record kinds or gate eras share has one code; the entry's `kind` names
1773
+ the record (`invalid` for one that does not parse).
1774
+ - Each code has one outcome, applied or refused, and an entry's `ok` is true exactly when its code is applied.
1775
+ - A code is upper snake case of at most 40 characters with a family prefix: RECORD, GATE, TOKEN, NAME, OFFER, BID,
1776
+ FILL, CLAIM, EXPIRY, TREASURY, CAP or INVARIANT.
1777
+ - Where a record breaks more than one rule, its code is that of the first rule in the reference implementation's order
1778
+ (`src/resolve/`, `src/records.ts`); `test/vectors/codes.json` pins the order where two rules meet.
1779
+ - An event that writes no entry has no code: an event below activation (§3); a repeated event at V29 or above (§32);
1780
+ an Attest on a proposal that is not an offer, except a cancel of a bid and a fill of a known fclaim; an Attest on an
1781
+ offer with a reserved score (any but 0, 50 and 100, and 50 below V17); and every expiry the sweep applies.
1782
+
1783
+ ### 40.2 Stability
1784
+
1785
+ A code in a release keeps its meaning: it is never renamed, never reused for another meaning and never removed; a code
1786
+ that is no longer written is marked retired and stays reserved. Codes may be added in any release, and a reason may be
1787
+ split into a new code only with a line in the changelog. The note text is a diagnostic and may change in any release.
1788
+ A consumer must treat an unknown code by its outcome (`ok`), since codes are added in any release.
1789
+
1790
+ ### 40.3 Caps
1791
+
1792
+ The caps are the per-address rules that count the proposer's other names or offers: CAP_PENDING_RESERVATIONS and
1793
+ CAP_PENDING_RECAPTURES (`MAX_PENDING_REG`), and CAP_LIVE_HOLDS (`MAX_ACTIVE_CLAIMS`, for fclaims and legacy claims).
1794
+ `CAP_CODES` lists them, for an alarm on any cap refusal. A bound on one record or one token is not a cap:
1795
+ TOKEN_SUPPLY_EXHAUSTED, EXPIRY_TOO_LONG, CLAIM_TOO_FAR_AHEAD, RECORD_TOO_LARGE and the profile limits.
1796
+
1797
+ ### 40.4 The table
1798
+
1799
+ Four codes guard a state no event reaches, so no vector holds them: NAME_RECLAIMED, NAME_RESERVATION_EXPIRED,
1800
+ NAME_NOT_LAPSED and INVARIANT_BROKEN (their rows say why).
1801
+
1802
+ | Code | Outcome | Cap | Meaning |
1803
+ |---|---|---|---|
1804
+ | TOKEN_DEPLOYED | applied | | a ticker is created |
1805
+ | TOKEN_MINTED | applied | | supply is credited to the minter (note: the amount) |
1806
+ | TOKEN_TRANSFERRED | applied | | tokens move |
1807
+ | TOKEN_META_SET | applied | | the issuer sets the metadata hash |
1808
+ | NAME_COMMITTED | applied | | a commit is recorded (its earliest height is kept) |
1809
+ | NAME_REGISTERED | applied | | a pay-now registration below V25, the name free |
1810
+ | NAME_REGISTERED_DISPLACED | applied | | a pay-now registration that displaces a holder with a later anchor |
1811
+ | NAME_RESERVED | applied | | a reservation (V25 and above) of a free name |
1812
+ | NAME_RESERVED_DISPLACED | applied | | a reservation that displaces a reservation with a later anchor |
1813
+ | NAME_RECAPTURE_RESERVED | applied | | a recapture reservation (V26 and above) of a lapsed name |
1814
+ | NAME_RECAPTURE_RESERVED_DISPLACED | applied | | a recapture reservation that displaces a later one |
1815
+ | NAME_RECLAIMED | applied | | a pay-now reclaim of a lapsed name below V26; no event reaches it, since the earliest lapse falls far above V26 |
1816
+ | NAME_FINALIZED | applied | | a registration is finalized and its fee paid |
1817
+ | NAME_RECAPTURE_FINALIZED | applied | | a recapture is finalized and its premium paid |
1818
+ | NAME_TRANSFERRED | applied | | the name has a new owner |
1819
+ | NAME_ADDR_SET | applied | | the address is set, or cleared by the zero address at V23 and above |
1820
+ | NAME_PROFILE_SET | applied | | the profile is set, or cleared by an empty `p` |
1821
+ | NAME_RENEWED | applied | | one term is added (note: the new paid-through epoch) |
1822
+ | OFFER_CREATED | applied | | an offer opens and its give is locked |
1823
+ | OFFER_BULK_CANCELLED | applied | | an ocancel applies (note: the count, which may be 0) |
1824
+ | OFFER_CANCELLED | applied | | a seller's cancel applies |
1825
+ | BID_CREATED | applied | | a bid opens |
1826
+ | BID_CANCELLED | applied | | a bidder's cancel applies |
1827
+ | FILL_APPLIED | applied | | a whole fill delivers (token-priced or CSD-priced) |
1828
+ | FILL_PARTIAL | applied | | a partial fill delivers, the one that completes the offer included (note: paid/want) |
1829
+ | CLAIM_GRANTED | applied | | an fclaim (kind fclaim) or a legacy claim (kind claim) holds the offer |
1830
+ | GATE_NOT_ACTIVE | refused | | the record type or shape is not active at this height |
1831
+ | CLAIM_LEGACY_SUNSET | refused | | a legacy claim attest at V28 or above |
1832
+ | TOKEN_TICKER_TAKEN | refused | | an earlier deploy holds the ticker |
1833
+ | TOKEN_UNKNOWN | refused | | the ticker, or an offer's want ticker, was never deployed |
1834
+ | TOKEN_NOT_ISSUER | refused | | an issuer-only mint or metadata record from another address |
1835
+ | TOKEN_SUPPLY_EXHAUSTED | refused | | nothing is left to mint |
1836
+ | TOKEN_MINT_AMOUNT_REQUIRED | refused | | an issuer mint without `amount` |
1837
+ | TOKEN_BALANCE_LOW | refused | | the available balance is short (a transfer, an offer's give, a token fill's price and fee) |
1838
+ | TREASURY_FEE_UNPAID | refused | | the output to the treasury is below the fee or premium (where the treasury is the seller on a rebate lane, below the fee plus the maker rebate, which sum on its output) |
1839
+ | NAME_NO_COMMIT | refused | | no commit for this reveal below its height and inside the window |
1840
+ | NAME_SALT_REQUIRED | refused | | a `name` without salt at V25 and above (registration) or V26 and above (recapture) |
1841
+ | NAME_TAKEN_EARLIER | refused | | an earlier (effective height, position, id) holds the name or its reservation |
1842
+ | NAME_TAKEN_PURCHASED | refused | | the holder bought the name in a fill and cannot be displaced |
1843
+ | NAME_SALT_MISMATCH | refused | | the finalize's salt does not re-derive the reservation's commit |
1844
+ | NAME_FINALIZE_TOO_EARLY | refused | | a finalize before the displacement freeze ends |
1845
+ | NAME_RESERVATION_EXPIRED | refused | | a finalize after finalizeBy; no event reaches it, since the sweep before each event drops the reservation and the late finalize gets NAME_NO_RESERVATION |
1846
+ | NAME_NOT_LAPSED | refused | | a recapture finalize of a name no longer lapsed; no event reaches it, since nothing makes a lapsed record live again before that finalize |
1847
+ | NAME_NO_RESERVATION | refused | | no reservation or recapture of this name owned by the proposer |
1848
+ | NAME_NOT_OWNER | refused | | the proposer does not own the name |
1849
+ | NAME_PENDING | refused | | the name is a reservation not yet finalized |
1850
+ | NAME_LAPSED | refused | | the lease and its grace are over |
1851
+ | NAME_NO_LIVE_LEASE | refused | | a renewal of an unknown or lapsed name |
1852
+ | NAME_GRACE_OWNER_ONLY | refused | | a renewal in grace by another address |
1853
+ | NAME_LOCKED | refused | | an open offer holds the name |
1854
+ | NAME_TOO_YOUNG | refused | | the sale embargo is not over |
1855
+ | OFFER_LEASE_TOO_SHORT | refused | | the lease ends before the offer expires |
1856
+ | OFFER_TAKER_REQUIRED | refused | | an open CSD-priced offer in [V13, V17) |
1857
+ | OFFER_PAYTO_TREASURY | refused | | the payto is the treasury |
1858
+ | OFFER_UNKNOWN | refused | | the fclaim names no known offer |
1859
+ | OFFER_NOT_OPEN | refused | | the offer is filled, cancelled or expired (note: the status) |
1860
+ | OFFER_NOT_SELLER | refused | | a cancel by another address |
1861
+ | OFFER_FIRM_QUOTE | refused | | a cancel of a taker-bound offer created at V28 or above |
1862
+ | OFFER_CANCEL_HOLD_LIVE | refused | | at the block boundary a deferred cancel meets a live fclaim hold |
1863
+ | OFFER_CLOSED_BEFORE_CANCEL | refused | | at the block boundary the offer is already closed (by a fill, or by an earlier cancel) |
1864
+ | BID_NOT_BIDDER | refused | | a bid cancel by another address |
1865
+ | BID_NOT_OPEN | refused | | the bid is cancelled, expired or done |
1866
+ | EXPIRY_UNSAFE | refused | | the expires_epoch is at or above 2^53 |
1867
+ | EXPIRY_PAST | refused | | the expiry epoch is before the inclusion epoch |
1868
+ | EXPIRY_TOO_LONG | refused | | the v2.1 duration cap (anchors in [V21, V22)) |
1869
+ | FILL_FCLAIM_NOT_CURRENT | refused | | a fill attests a denied or superseded fclaim: the payment moves, nothing is delivered |
1870
+ | FILL_NOT_TAKER | refused | | the filler is not the bound taker |
1871
+ | FILL_NO_TOKEN_MARKER | refused | | a token-priced fill without confidence `CONF_TOKEN_FILL` |
1872
+ | FILL_OPEN_LANE_CLOSED | refused | | an open CSD fill in [V13, V17) |
1873
+ | FILL_WRONG_TARGET | refused | | an offer-id fill during an fclaim hold |
1874
+ | FILL_NO_LIVE_CLAIM | refused | | an open CSD fill without the filler's live hold |
1875
+ | FILL_BELOW_MIN | refused | | a partial payment below the effective minimum |
1876
+ | FILL_ZERO_DELIVERY | refused | | the payment delivers no unit |
1877
+ | FILL_UNDERPAID | refused | | the payment to payto is below want.value (where payto is the seller and a maker rebate applies, a shortfall there is FILL_REBATE_UNPAID) |
1878
+ | FILL_REBATE_UNPAID | refused | | the payment to the seller is below the maker rebate, or, where payto is the seller, below want.value plus the rebate |
1879
+ | CLAIM_TAKER_BOUND | refused | | a taker-bound offer takes no claim |
1880
+ | CLAIM_TOKEN_PRICED | refused | | claims are for CSD-priced offers |
1881
+ | CLAIM_HOLD_LIVE | refused | | a hold (window and grace) is live, whoever holds it |
1882
+ | CLAIM_COOLDOWN | refused | | the last holder within `CLAIM_COOLDOWN_BLOCKS` of its hold's end |
1883
+ | CLAIM_OUTLIVES_OFFER | refused | | the hold's expiry is after the offer's |
1884
+ | CLAIM_TOO_FAR_AHEAD | refused | | the hold's expiry is more than `FCLAIM_MAX_EPOCH_AHEAD` epochs ahead |
1885
+ | CAP_PENDING_RESERVATIONS | refused | yes | the proposer holds `MAX_PENDING_REG` other live reservations |
1886
+ | CAP_PENDING_RECAPTURES | refused | yes | the proposer holds `MAX_PENDING_REG` other live recapture reservations |
1887
+ | CAP_LIVE_HOLDS | refused | yes | the proposer holds `MAX_ACTIVE_CLAIMS` live holds |
1888
+ | INVARIANT_BROKEN | refused | | an open offer's name or give lock is missing; no event reaches it |
1889
+ | RECORD_TOO_LARGE | refused | | the uri is over `MAX_RECORD_BYTES` UTF-8 bytes |
1890
+ | RECORD_NOT_OBJECT | refused | | the uri is not JSON, or not a JSON object |
1891
+ | RECORD_NOT_CANONICAL | refused | | the uri is not the canonical JSON of its object |
1892
+ | RECORD_HASH_MISMATCH | refused | | the payload hash does not commit to the uri |
1893
+ | RECORD_LONE_SURROGATE | refused | | a string holds a lone surrogate |
1894
+ | RECORD_NOT_V1 | refused | | `v` is not 1, or `t` is not a string |
1895
+ | RECORD_UNKNOWN_TYPE | refused | | an unknown `t` |
1896
+ | RECORD_EXTRA_KEY | refused | | a key outside the record's set |
1897
+ | RECORD_BAD_SHAPE | refused | | the fields form none of the record's allowed shapes |
1898
+ | RECORD_SAME_TOKEN | refused | | the give and the want are one ticker |
1899
+ | RECORD_BAD_TICKER | refused | | a ticker is missing or does not match `TICKER_RE` |
1900
+ | RECORD_BAD_NAME | refused | | a name is missing or does not match `NAME_RE` |
1901
+ | RECORD_NAME_RESERVED | refused | | a name in `RESERVED_NAMES` |
1902
+ | RECORD_BAD_ADDRESS | refused | | an address is missing or does not match `ADDR_RE` |
1903
+ | RECORD_BAD_AMOUNT | refused | | an amount is missing or not a canonical decimal string |
1904
+ | RECORD_AMOUNT_TOO_LARGE | refused | | an amount at or above 2^96 |
1905
+ | RECORD_AMOUNT_ZERO | refused | | an amount of 0 where zero is refused |
1906
+ | RECORD_MIN_ABOVE_WANT | refused | | the offer's `min` is above want.value |
1907
+ | RECORD_BAD_HASH | refused | | a hash is missing or does not match `HASH_RE` |
1908
+ | RECORD_BAD_SALT | refused | | a salt does not match `SALT_RE` |
1909
+ | RECORD_BAD_DECIMALS | refused | | the decimals are not an integer from 0 to `MAX_TOKEN_DECIMALS` |
1910
+ | RECORD_BAD_MINT_MODE | refused | | the mint is neither open nor issuer |
1911
+ | RECORD_BAD_TEXT | refused | | a memo or token name is not a string or is too long (in UTF-16 units) |
1912
+ | RECORD_BAD_TS | refused | | the ts is not a safe integer |
1913
+ | RECORD_PROFILE_TOO_MANY_KEYS | refused | | a profile over `PROFILE_MAX_KEYS` keys |
1914
+ | RECORD_PROFILE_BAD_KEY | refused | | a profile key that does not match `PKEY` |
1915
+ | RECORD_PROFILE_BAD_VALUE | refused | | a profile value that is not a string |
1916
+ | RECORD_PROFILE_VALUE_TOO_LONG | refused | | a profile value over `PROFILE_MAX_VALUE_BYTES` UTF-8 bytes |
1917
+
1918
+ ### 40.5 Records and builders
1919
+
1920
+ `explainRecord(uri, payloadHash)` answers `{ ok: true, record }` or `{ ok: false, code }`, and `parseRecord` answers
1921
+ null exactly when it answers a code. A record builder that refuses throws `RecordError`, an `Error` whose `code` is the
1922
+ record code and whose message is `record does not validate against CONVENTION.md (<code>)`. A builder input that is not
1923
+ JSON data throws the codec's own error before any rule is checked.
1924
+
1925
+ ### 40.6 The client helpers' reasons
1926
+
1927
+ `previewFill` and `fillOutputPlan` keep their own reasons: `not-open` is OFFER_NOT_OPEN, `zero-delivery` is
1928
+ FILL_ZERO_DELIVERY, and `below-min` is FILL_BELOW_MIN on a partial fill and FILL_UNDERPAID on a whole one.
1929
+
1930
+ ### 40.7 Reference and vectors
1931
+
1932
+ `src/codes.ts` holds the table: `REASON_CODES`, `REASON_CODE_OUTCOME`, `CAP_CODES` and the types `ReasonCode`,
1933
+ `AppliedCode`, `RefusalCode` and `RecordCode`; a test requires it equal to §40.4. `test/vectors/codes.json` holds 145
1934
+ resolve cases (the events, the tip and the expected entries as `[id, kind, ok, code]`, compared as a set) and 50 record
1935
+ cases (the uri, the payload hash and the expected code, or null for a record that parses), with every expectation
1936
+ written by hand in `conformance/gen-codes-vectors.mjs`. A replica that publishes codes reproduces it. The Python
1937
+ reference of `conformance/` writes no codes.
1938
+
1939
+ ---
1940
+
1941
+ # Token moves (no gate)
1942
+
1943
+ ## 41. Token moves
1944
+
1945
+ An applied entry of the log (§5) whose record moved tokens carries `moves`: the movements in the order the record
1946
+ applied them, each `{ leg, ticker, from, to, amount }`, that is `amount` base units of `ticker` from the address `from`
1947
+ to the address `to`. `amount` is a positive decimal string in the form of the state's balances (§5). The resolver
1948
+ writes each move where it applies the balance change, so a reader takes who received what from the log and does not
1949
+ restate the rules that decide the amounts (the mint caps, a whole fill's delivery, the partial fill's floor, the fee).
1950
+
1951
+ | leg | written by | from | to | amount |
1952
+ |---|---|---|---|---|
1953
+ | `mint` | an applied mint (§4.2) | null | the proposer | the credit: `min(amount, mintLimit, remaining)` for an open mint, `amount` defaulting to `mintLimit`; `min(amount, remaining)` for an issuer mint |
1954
+ | `xfer` | an applied transfer (§4.3) | the proposer | `to` | `amount` |
1955
+ | `sale` | an applied fill of a token-priced offer (§11) | the buyer | `want.payto` | `want.amount`, the fill's `paid` (§5) |
1956
+ | `fee` | the same fill | the buyer | the treasury (§10) | the fill's `fee` |
1957
+ | `fill` | an applied fill of an offer whose give is a token (§4.5, §11, §12) | the seller | the buyer | `give.amount` on a whole fill, the `got` of its `fills` entry on a partial one (§12) |
1958
+
1959
+ - A token-priced fill writes its sale, then its fee, then its give. A zero amount writes no move: the sale of a token
1960
+ priced at `"0"` (§11) and its fee of 0.
1961
+ - An offer, a cancel, an `ocancel` and an expiry move tokens between one address's `available` and `locked` and write
1962
+ no move; nor does a fill that moves no token (a name sold for CSD), nor any other record. A refused entry carries no
1963
+ moves. An entry with no move has no `moves` key, and `moves` is its last key.
1964
+ - In one result a ticker names one token: the first anchored deploy of a ticker wins and a later one is refused (§4.1),
1965
+ and no record removes a token. A replay of another chain, after a reorganisation below the deploy, can bind the
1966
+ ticker to another deploy. So a move carries no deploy id; `tokens[ticker].deployId` of the same result gives it.
1967
+ - The identity the moves meet: for every ticker and address, the amounts the address received less the amounts it
1968
+ sent, over every move of the log, equal its `available` plus `locked` in `balances`, an address left out of
1969
+ `balances` holding 0; and the mint moves of a ticker sum to its `minted`.
1970
+ - The log is outside canonical state (§5), so moves change no state hash, and a replica that writes no moves conforms
1971
+ at every level of §38. A replica that publishes moves reproduces `test/vectors/moves.json`.
1972
+
1973
+ `TokenMove` (`src/types.ts`) is the type; `src/resolve/tokens.ts` and `src/resolve/attest.ts` write the moves.
1974
+ `test/vectors/moves.json` holds 13 cases (the events, the tip, and the entries that carry moves with their moves, in
1975
+ log order), every expectation written by hand in `conformance/gen-moves-vectors.mjs`. `conformance/moves-check.mjs`
1976
+ checks a result's moves against its input events and its state by the rules above, each transfer's and mint's move
1977
+ against its own record; the cairnx-core tests run it over the replay corpus at
1978
+ every pinned height and over every case file, and the seal over every input of its differential. The Python reference
1979
+ of `conformance/` writes no moves.