CBCL / DocumentationDocs v0.3.1

Canonical encoding and identity

This reference describes dialect signing form 8, message typed-address form 2, and the v3 root attestation. Each version identifies a different operation. The inputs below start with a parsed CBCL value. Use the ABNF and scanner rules to obtain that value.

To computeInput
Dialect self-addressSHA-256 of the canonical dialect projection with an empty name string
Named dialect integrity hashSHA-256 of the same projection with the actual name
R4 dialect signatureThe complete canonical bytes of the named projection
Message content addressThe root of a fixed six-leaf Merkle tree over structured message fields
V3 message signatureA canonical list containing the domain, suite, and rendered message address

Render a 32-byte SHA-256 digest as lowercase base16 multibase over a multihash: the character f, then hex for bytes 12 20 (SHA2-256 code and digest length), then 64 lowercase hex digits. In the algorithms below, addr(digest) means this rendering. It performs no additional hash.

On this page

Encode a typed value

Let E(x) return bytes. For a list, emit ASCII (, then each child’s encoding in sequence, then ASCII ). For an atom, construct the payload below and emit its byte count in unsigned decimal ASCII, a colon, and the payload. Use minimal length digits. Counts include the one-byte ASCII tag. There are no separators or final newline.

AtomPayloadExample encoding
SymbolS + UTF-8 nametell → 5:Stell
KeywordK + UTF-8 name without its leading colon:x → 2:Kx
StringQ + decoded UTF-8, preserving scalar sequence"é" → hex 33 3a 51 c3 a9
IntegerN + minimal signed base-ten digits, zero as 0-0 → 2:N0
Finite binary64F + shortest round-tripping decimal significand rendered in fixed point1e2 → 6:F100.0
Exact decimalD + normalized fixed-point decimal, omitting the source suffix001.2500m → 5:D1.25
BooleanBt or Bf#t → 2:Bt

For binary64, collapse both signed zeroes to 0.0. Choose the closest shortest decimal that rounds to the value under round-to-nearest, ties-to-even. When two shortest decimals are equally close, the current formatter chooses the greater magnitude. Expand powers of ten and append .0 when the result is integral. For exact decimals, strip leading integer zeroes and trailing fractional zeroes, keeping one integer digit and dropping an empty fractional part. Decimal zero is 0. Treat integer, float and decimal as distinct throughout.

Build the dialect signing form

The following layout describes an internal typed S-expression. Literal heads are symbols, quoted fields are strings, and an ellipsis stands for zero or more children. Build the seven required segments in this order after the head and name (the profile through examples):

(dialect "name"
  (type-profile "cbcl-flat-v1-unicode16")
  (types (local-name type-expression) ...)
  (extends "parent" ...)
  (author "author")
  (performatives (perf "verb" (params parameter ...) template [role-annotation]) ...)
  (resources depth expansion-size)
  (examples example ...))

Keep every displayed segment, including empty lists with their heads. An absent author gives (author). Type names are symbols sorted by name. Type expressions, parameters, templates and examples retain their typed trees. Preserve the order of parents, performatives, parameters and examples. Resource values are integer atoms. For an authored dialect, omitted bounds default to 16 and 1024. Omit integrity metadata (:signature, :hash, and the keyword :protocol signature-algorithm declaration). The symbol-headed causal protocol has its own signed segment.

Append optional segments after examples in the following order. Compare names by unsigned UTF-8 bytes, with no locale collation. The version number itself contributes no bytes.

  1. Causal protocol, when present. Emit (causal-protocol (step "verb" (predecessors ref ...) (successors ref ...)) ...) from the expanded protocol graph. Sort steps by verb. Preserve each adjacency list’s order as edges are added from the parsed chains. Encode references as (single "verb"), (any "verb" ...), or (all "verb" ...), with set members sorted. A present empty graph emits (causal-protocol).
  2. Shapes, when nonempty. Emit (shapes (shape "verb" rule ...) ...). Encode a rule as (require "key" (type [expr]) child ...), (optional "key" (type [expr]) (default [value]) child ...), or (max-depth integer). Key strings omit the colon. Use the built-in type symbol or the stored contract expression. Normalize child lists first. At every level sort field rules before depth rules, field rules by key, then ties by the full encoded rule bytes. Sort shapes by verb, then by their full normalized bytes.
  3. Roles, when nonempty. Emit (roles (role-decl "name" singleton-or-indexed) ...) in declaration order, using the literal symbol singleton or indexed. An annotated performative also has a final child (role (from "role") (to "role" ...)) inside its own perf list. Sort the recipient role set.
  4. Causal locality, for derive mode. Emit (causal-locality derive). Default reject mode contributes zero children.
  5. State, when present. Emit (state entry ...) in declaration order, using the projections below.
  6. State bounds, when present. Emit (state-bounds max-string max-list max-number max-fields) with all four resolved integer values.

State entry projections

For an ordinary field emit (field "name" (rule-head arg ...)). The head is a symbol. For ordinary register, set, map, event, counter, progress, histogram, sum and context rules, emit their declared arguments in grammar order as strings, removing the keyword colon from field keys. Include optional delete verbs only when present. The specialized entries have the following layouts. See the state language reference for the rule arguments.

EntrySigned projection
Domain(domain "verb" "key" "field")
Freeze(freeze "field" "verb" policy) with the resolved policy symbol
Threshold(threshold "name" "field" element ...) or (threshold "name" condition). A read is (read field-symbol element). An and retains child order. Elements retain scalar types or use their tagged list, such as (count 2).
Finite lattice(lattice name (elements e ...) (bottom e) (top e) (join (a b c) ...)). Names and elements are symbols. Retain element and row order.
Lift fieldInside its field wrapper use (lift verb (into lattice) (contribute (:key scalar element) ...) [projection]). The optional projection is (project [stable] ((element scalar) ...)). Verbs and element names are symbols. Preserve row order.
Bounded-counter fieldInside its field wrapper use the surface option lists in the fixed order below. Verbs and roles are symbols, keys are keywords, bounds are integers, and an empty issuer set is ().

Bounded-counter option order is floor, ceiling if present, certification if emitted, ownership for collective mode, initial-rights (account) or initial (collective), initial-headroom if present, issuers, increment, decrement, transfer if present, transfer-headroom if present. Host-gate certification contributes no option. Quorum certification emits (certification quorum-budget [(validators key ...)] [(faults n)]), sorting explicit validator symbols and emitting the resolved fault bound for an explicit valid committee (default (size - 1) / 3). With no explicit roster, include faults only when supplied.

Worked dialect, from source to signature input

Start with the following authored dialect. To issue it under its self-address, first project it with the name set to the empty string. The empty name still occupies a string atom.

(define demo (cbcl) @alice (extend ping (x) (tell x)))

The exact bytes to hash for the self-address are the single ASCII line below, excluding the line ending.

(8:Sdialect1:Q(13:Stype-profile23:Qcbcl-flat-v1-unicode16)(6:Stypes)(8:Sextends5:Qcbcl)(7:Sauthor7:Q@alice)(14:Sperformatives(5:Sperf5:Qping(7:Sparams2:Sx)(5:Stell2:Sx)))(10:Sresources3:N165:N1024)(9:Sexamples))

Applying addr(SHA256(bytes)) gives f122056ba1fad556a3749faffdc4a478c78038320d65ef0fdaabaafcda29c8904c95f. Replace the dialect name with that entire string and project again. The following line is the exact R4 signature input for the self-addressed dialect.

(8:Sdialect70:Qf122056ba1fad556a3749faffdc4a478c78038320d65ef0fdaabaafcda29c8904c95f(13:Stype-profile23:Qcbcl-flat-v1-unicode16)(6:Stypes)(8:Sextends5:Qcbcl)(7:Sauthor7:Q@alice)(14:Sperformatives(5:Sperf5:Qping(7:Sparams2:Sx)(5:Stell2:Sx)))(10:Sresources3:N165:N1024)(9:Sexamples))

Applying addr(SHA256(signature_input)) gives the named integrity hash f1220f02a24f8c54394348e94ee844d21b0ee93d5ec13bf5004b3f02ae02a3c9c2821. Pass the displayed signature input directly to the selected signing algorithm. To issue a dialect under the alias demo, retain demo in the name slot for signing and integrity hashing. The empty-name calculation still gives the same self-address. Signing-form migration vector

Compute a message address

Extract these six typed values from the parsed message. For each field, construct a two-child list containing its domain tag as a symbol and its value. The literal tags retain the spelling v1 in typed-address form 2.

IndexExact tagValue for a simple message
0cbcl-taddr-v1/field-0-performativePerformative symbol
1cbcl-taddr-v1/field-1-fromEmpty list for absent sender, otherwise a one-element list containing the sender string
2cbcl-taddr-v1/field-2-toSorted list of distinct recipient symbols
3cbcl-taddr-v1/field-3-caused-byEmpty list if absent. Otherwise wrap one value in a list: the symbol begin, a single address symbol, or a sorted list of address symbols. Multiple references retain duplicates.
4cbcl-taddr-v1/field-4-threadEmpty list for absent thread, otherwise a one-element list containing the thread string
5cbcl-taddr-v1/field-5-payloadList starting with content (default empty list), followed by normalized parameters

To normalize parameters, scan left to right, consuming each keyword and its value as a pair. Sort pairs by keyword name and write them back into the original pair slots. Positional values stay at their original indices. For instance, the parameter tail :z 1 x :a 2 becomes :a 2 x :z 1.

For meta, dialect-scoped, and wrapped messages, field 0 is the outer head symbol, fields 1–4 are empty lists, and field 5 is a one-element list containing the structured whole-message projection. Reconstruct it as (meta operation), (lang dialect-symbol inner), or (wrapper normalized-params ... inner), recursively projecting the inner message. A nested simple message emits its performative, optional recipient (single symbol or sorted recipient list), content, normalized parameters, then the present reserved keyword/value pairs in order :thread, :sender, :caused-by. Use strings for thread and sender and the causal value from field 3 without its optional-field wrapper.

With raw 32-byte intermediate hashes, compute:

L[i] = SHA256(0x00 || E((tag[i] value[i])))
N(a,b) = SHA256(0x01 || a || b)
root = N(N(N(L[0],L[1]), N(L[2],L[3])), N(L[4],L[5]))
message_address = addr(root)

For (tell @bob "hi" :sender @alice) the six values in order are tell, ("@alice"), (@bob), (), (), and ("hi"). The resulting address is f1220512d1642481f51ea096d3b2e07d5717523e044415ba33fd10cd77290de39bd47.

A v3 attestation signs E((cbcl-attest-v3 suite message-address)), with all three children symbols. For the example above and suite ed25519, the signature input is:

(15:Scbcl-attest-v38:Sed2551970:Sf1220512d1642481f51ea096d3b2e07d5717523e044415ba33fd10cd77290de39bd47)

Verify using the declared discipline. The v1 full-bytes discipline takes the supplied full message bytes. The v2 header discipline encodes (cbcl-attest-v2 suite content-hash performative from (to ...) "thread" [caused-by]), with suite-explicit canonical key symbols, recipient keys in set order, and causal references encoded as above. These message attestations and R4 dialect signatures use distinct preimages.

Address used by a state act

For a state predecessor reference, first select the identity subtree, then compute its message address. Inspect the innermost simple message. An act with a predecessor address uses that simple message. For a root (absent causal reference, begin, or an internally constructed empty predecessor list), walk inward from the outer message through dialect and wrapper nodes. Use the first with-roles subtree encountered, including its cast and inner message. If there is no such wrapper, use the simple message. Consequently, a cast-bearing root and its unwrapped simple message can have different addresses even when they carry the same content.