Bundle format, versions 1 and 2¶
This page specifies bundle versions 1 and 2: the file that export_bundle() writes and verify_bundle() checks (see exporting a bundle and verifying a bundle offline). It covers every entry and field of the file, the manifest and what anchors it, the verification algorithm step by step, and every finding a bundle verifier reports. With it and the test vectors, a bundle verifier can be written in another language.
Version 2 is version 1 with one more erasable group, state (data.state, the row a model with record_state stores). A writer MUST write version 2 when at least one activity row it exports has a data.state key, and version 1 otherwise; the reference writer decides with a scan of the rows in scope before it writes header.json. A version 1 bundle is byte for byte what a writer without state writes. Everything this page says holds for both versions, except where it names state, which only version 2 has. A reader that knows only version 1 refuses a version 2 bundle by its bundle_version.
The canonical JSON encoding, commitments, leaf hashes, segment roots, block hashes, the members of each block body and the retire digest are specified in the canonical encoding spec. This page relies on it and does not repeat it.
Conventions¶
The key words MUST, MUST NOT, SHOULD and MAY are to be read as in RFC 2119 and RFC 8174 when, and only when, they appear in capitals.
SHA-256(x)is the 32-byte SHA-256 digest of the bytesx,||is byte concatenation, and0x00is a single byte. A quoted string such as"sqlalchemy-audit-trail/leaf/v1"stands for its ASCII bytes.canonical(v)is the canonical encoding of the JSON valuev, as the canonical encoding spec defines it, within its limits.- base64 is standard base64 (RFC 4648, section 4) with
=padding. A reader decodes it strictly: a character outside the alphabet, or wrong padding, is an error. - A timestamp is UTC text with six fraction digits and
Z,YYYY-MM-DDTHH:MM:SS.ffffffZ. A writer MUST write this form and a reader MUST accept it. A timestamp in another form is outside version 1, and a reader MAY refuse the bundle as malformed. The reference reader is more lenient: it accepts any date and time that Python'sdatetime.fromisoformatreads and that ends inZ. - JSON is RFC 8259 JSON. A writer MUST NOT write
NaN,Infinityor-Infinity, nor an object with two equal keys. A bundle that holds one is outside version 1, and a reader MAY refuse it as malformed. The reference reader accepts the non-finite numbers and keeps the last of two equal keys. - Numbers. A reader MUST parse every number of the bundle exactly, as the canonical encoding spec requires of a reader of stored JSON: an integer of up to 4300 digits whatever its runtime settings, and a number with a fraction or an exponent as an exact decimal, never as an IEEE 754 binary64 double. A reader that rounds a number, or refuses a long integer, can report
COMMITMENT_MISMATCHfor a valid row, or refuse a valid bundle as malformed. The reference reader parses numbers exactly. - An integer is a JSON number without a fraction or exponent.
trueandfalseare not integers. - A stream is
transaction, oractivity.<severity>with the severity as a decimal integer without leading zeros, such asactivity.20. A partition is the name of a partition of an audit table, without a schema. - Failing means adding a finding of a failure kind to the report, and noting means adding a finding of a note kind. Neither stops the verification. Every finding is collected.
What a bundle shows¶
A bundle holds a range of blocks of one chain (the scope), the block before it, and every row the seal blocks in scope seal, with everything needed to check them without the database. A verifier checks that the blocks are one unbroken range of the chain, that the rows are exactly the ones the seal blocks sealed, and that every erased value was erased by a recorded scrub.
Trust comes only from what the verifier is given: the keys it trusts, trusted checkpoints, a key history and a manifest hash. The keys, key ids, key history and checkpoints inside a bundle MUST NOT establish trust by themselves. A bundle that only matches itself proves that whoever wrote it was consistent, not that it is the chain: anyone who can write a bundle can write a consistent forgery. A trusted checkpoint naming a block of the bundle, or trusted block signatures, tie it to the real chain.
Layout¶
A bundle is a zip file (APPNOTE). Its entries MUST be these, in this order, each exactly once:
| # | Entry | Holds |
|---|---|---|
| 1 | header.json |
One JSON object: the version, the chain and the scope |
| 2 | blocks.jsonl |
The block before the scope and the blocks in scope |
| 3 | retired.jsonl |
Retire blocks after the scope that explain missing rows |
| 4 | rows.jsonl |
The rows the seal blocks in scope seal |
| 5 | scrubs.jsonl |
The audit.scrubbed records the erasure stamps name |
| 6 | checkpoints.jsonl |
Checkpoints, as signed notes |
| 7 | keys.json |
One JSON object: key ids and a key history |
| 8 | host/<name> |
Zero or more files of the writer, byte for byte |
| 9 | manifest.note |
The SHA-256 and size of every other entry, as a signed note |
Entries 1 to 7 and 9 are always present, also when empty. The order lets a reader hold one seal block's segment trees at a time while it reads rows.jsonl; it does not let it check the bundle in one front-to-back pass. A reader needs random access to the zip: the reference verifier reads manifest.note, header.json and checkpoints.jsonl before blocks.jsonl. Every entry between keys.json and manifest.note MUST have a name that starts with host/ and does not end with /. The writer of this package also limits a host name to at most 200 bytes of /-separated parts of ASCII letters, digits, ., _ and -, none of them . or ..; a reader MUST NOT rely on that.
A writer MAY compress entries with deflate or store them; a reader MUST accept both. A writer SHOULD give every entry a fixed time, so that the same content gives the same file. The reference writer deflates every entry and gives it the time 1980-01-01 00:00:00.
A .jsonl entry holds one JSON object per line, each line ending in a newline (0x0A), the last one included. An empty .jsonl entry has no lines. A writer MUST write each line as canonical(object) followed by the newline, and each .json entry as canonical(object) without a newline. A reader MUST NOT require canonical lines: their bytes are covered by the manifest, and every hash the verification checks is over bytes the bundle carries, never over a re-encoding of a line.
A line, a .json entry and manifest.note are at most 64 MiB (67,108,864 bytes), the newline included. A reader MAY refuse a longer one; the reference reader does.
header.json¶
| Field | Value |
|---|---|
bundle_version |
1, or 2 when a row record holds the state group or null key (see versions) |
stream_type |
"audit": the rows are rows of the audit tables. Another kind of rows gets another value, not another bundle version: "ledger" is a ledger chain, laid out as the ledger format spec says |
chain |
The chain id, the chain of every block body |
scope |
An object: first and last, the seq of the first and last block in scope; previous, the seq of the block before them, null when first is 1; time, {"start": timestamp, "end": timestamp} when the writer was given a time range, else null |
tables |
The tables whose rows are included, sorted: one or both of "activity" and "transaction" |
created_at |
A timestamp: when the bundle was written |
A reader MUST check that first is at least 1, last is at least first, and previous is first - 1 when first is above 1 and null when it is 1. A time range selects the blocks whose sealed_at is in [start, end). No field of the header is hashed into the chain: a reader can check that the blocks are an unbroken range of the chain, not that they were written in the time range, nor when the bundle was written. A reader does not read created_at.
blocks.jsonl¶
Every block from previous (or from first when previous is null) to last, in seq order, of every kind, one block record per line:
| Field | Value |
|---|---|
seq |
Integer: the block number |
kind |
Text: the kind column, one of genesis, seal, checkpoint, fork, retire and ack |
body |
base64 of the stored body bytes, exactly as hashed |
prev_hash |
base64 of the stored prev_hash, 32 bytes |
block_hash |
base64 of the stored block_hash, 32 bytes |
sealed_at |
A timestamp: when the block was written. Not hashed |
signature |
base64 of the block signature, or null |
key_id |
Text: the key id of the signer, or null |
alg |
Text: "ed25519" or "ecdsa-p256-sha256", or null |
signature, key_id and alg are all null for an unsigned block. The body, its hash and the members of each kind are those of the canonical encoding spec.
The first line is the block before the scope when previous is not null. Its block_hash is the link the first block in scope is checked against. Its own prev_hash is not checked, since the block before it is not in the bundle; its hash, its body and its signature are (see resuming).
retired.jsonl¶
Retire blocks after last that retire a partition named by a segment of a seal block in scope, in seq order, as block records. They explain the rows of such a partition that are gone. Their link to the chain is outside the bundle: a retire block here explains rows only when a trusted checkpoint names it, with its hash, or a trusted key signed it.
rows.jsonl¶
For each seal block in scope, in seq order, and for each table included, the rows the block seals, in (xid, id) order: the transaction rows of the block first, then its activity rows. One row record per line:
| Field | Value |
|---|---|
seq |
Integer: the seal block that seals the row |
table |
"transaction" or "activity" |
stream |
The row's stream |
partition |
The partition that holds the row |
id |
Integer: the row's id |
xid |
Integer: the row's xid |
leaf |
Text: the canonical leaf row, exactly the bytes its leaf hash is over, or null |
groups |
An object from group name to text, or null |
nulls |
An array of text |
salts |
The row's seal_salts as stored: an object from group name to base64, or null |
erased |
The row's seal_erased as stored: an object from group name to the erasure stamp, or null |
leafiscanonical(leaf row)decoded as UTF-8, where the leaf row is the one of the canonical encoding spec. A reader MUST hash the UTF-8 bytes of this text as they are:SHA-256(0x00 || "sqlalchemy-audit-trail/leaf/v1" || UTF-8(leaf)). It MUST NOT parse and re-encode it to hash it.leafisnullwhen the stored row has no canonical encoding.groupsholds each erasable group of the row that has a value, ascanonical(value)decoded as UTF-8: the text the group's commitment is over. The groups arelabel,changes,payload,state(version 2 only) andactorfor an activity row andactorfor a transaction row, with their values as in the canonical encoding spec. A group a scrub erased holds what the scrub left.groupsisnullwhen the values have no canonical encoding.nullslists the erasable keys of an activity row'sdatastored as JSONnull, which no group holds:changes,payload,state(version 2 only), andcontext.<field>for each fieldactor_label,remote_addr,user_agentandmetaofdata.context, in that order. It is[]when there are none and for every transaction row. Withgroupsand the leaf it gives the erasable parts exactly as stored, which the erased form of a scrubbed group is checked on: a key stored asnullis not erased, an absent key is.saltsanderasedare the stored values. A scrub deletes the salt of each group it erases and stamps the group inerasedwith thexidof its own transaction, as decimal text.
The leaf row holds seal_commitments, so an erased group stays covered by its commitment and its stamp. A segment's root is the Merkle tree hash of the leaf hashes of its rows, per (seq, stream, partition), as in the canonical encoding spec. A segment with fewer rows in the bundle than its block names lost them, unless a retire block retired its partition.
scrubs.jsonl¶
The audit.scrubbed records whose xid an erasure stamp of a row in rows.jsonl names, in (xid, id) order, as row records. Here seq is the seal block that seals the record, or null when no block seals it yet. A record also in rows.jsonl appears in both, with the same leaf. A record sealed outside the scope is evidence of the scrub, counted but not checked against a root.
checkpoints.jsonl¶
One checkpoint per line:
| Field | Value |
|---|---|
source |
"given" for a checkpoint the writer was given, "chain" for one recorded in a checkpoint block that names a block in blocks.jsonl |
block |
Integer: the seq of that checkpoint block, for "chain"; null for "given" |
note |
Text: the checkpoint, as a signed note |
A checkpoint here is used only when it carries a signature of a key the verifier trusts. source and block are informative; a reader checks only their types.
keys.json¶
| Field | Value |
|---|---|
key_ids |
Sorted array of text: every key id that signed a block, a checkpoint or the manifest of the bundle |
history |
The key history the writer was given, {key_id: {"valid_from": n, "retired_at": n or null, "compromised_from": n or null}}, or null |
Keys appear by id only, with no key material. A reader MUST NOT trust a key, or a key history, because the bundle names it. The reader checks only that key_ids is an array of text and history is an object or null.
host/<name>¶
Files the writer added, byte for byte. They are covered by the manifest, and only as far as the manifest is anchored.
manifest.note¶
A signed note whose text is two lines:
sqlalchemy-audit-trail/bundle-manifest/v1
{"bundle_version":1,"chain":"<chain id>","files":[{"name":"header.json","sha256":"<base64>","size":123},...]}
The second line is canonical({"bundle_version": 1, "chain": ..., "files": [...]}), with the header's bundle_version (2 for a version 2 bundle). files lists every other entry, in zip order, each with its name, the base64 SHA-256 of its bytes (uncompressed) and its size in bytes. The writer signs the note with its signer when it has one; otherwise the note is the text alone, with no signature line.
Signed notes and signatures¶
Signed notes¶
Checkpoints and the manifest travel as C2SP signed notes: UTF-8 text with no control character but the newline, ending in a newline; then, when signed, a blank line and one or more signature lines — <key name> <base64(key hash || signature)>, each ending in a newline, where — is U+2014 and the key hash is 4 bytes. A note without a blank line is a text with no signature. The base64 of a signature line MUST be canonical, and decode to more than 4 bytes. A key name is non-empty, with no Unicode space and no +. A note has at most 100 signature lines.
A verifier checks a note's signatures with the keys it trusts:
- Each signature line names a key id,
<key name>+<key hash as 8 lowercase hex digits>. Lines of keys the verifier does not know are ignored. - Two lines of one known key make the note malformed.
- A line of a known key whose signature over the note text (the bytes up to and including the newline before the blank line) does not verify makes the note fail with bad signature.
- A note with no verified signature of a known key fails with unknown key; an unsigned note does too.
Keys and block signatures¶
A key id is <key name>+<key hash>, the key hash as 8 lowercase hex digits. The key hash is SHA-256(key name || 0x0A || 0x01 || public key)[:4] for an Ed25519 key, and SHA-256(DER SubjectPublicKeyInfo)[:4] for an ECDSA P-256 key, as the C2SP signature types 0x01 and 0x02 assign them. A verifier key is written <key id>+<base64(type byte || public key)>. The public key of an Ed25519 key is its 32 bytes (RFC 8032). The public key of an ECDSA P-256 key is its DER SubjectPublicKeyInfo (RFC 5480): algorithm id-ecPublicKey with the named curve secp256r1 (P-256), and the point uncompressed (0x04 || X || Y, 65 bytes), 91 bytes in all; it is what Go's x509.MarshalPKIXPublicKey writes. A verifier MUST refuse another encoding of the same key, such as a compressed point, explicit curve parameters or BER, so that every verifier derives the same key hash from the same text.
A block signature is over
with the stored block_hash. An Ed25519 signature is the 64-byte signature of RFC 8032. An ECDSA P-256 signature is the DER ECDSA-Sig-Value (SEQUENCE { r INTEGER, s INTEGER }) over the SHA-256 digest of the message; another encoding of the same (r, s) does not verify. A note signature uses the same algorithms over the note text.
Checkpoints¶
A checkpoint note's text is a statement, versioned by its first line, followed by zero or more extension lines.
Statement version 1 is two lines:
sqlalchemy-audit-trail/checkpoint/v1
{"block_hash":"<base64>","chain":"<chain id>","incarnation":1,"sealed_at":"<timestamp>","seq":3,"v":1,"xid_to":120}
The second line is the canonical encoding of an object with exactly the members v (1), chain (text), seq (an integer of at least 1), block_hash (base64 of 32 bytes), xid_to (integer), sealed_at (a timestamp) and incarnation (an integer of at least 1). A reader MUST refuse a statement whose second line is not exactly that canonical encoding. The checkpoint names block seq of chain chain with its hash, the sealed horizon xid_to, and the incarnation the chain was in when it was taken.
Statement version 2 is three lines, written for a checkpoint that commits to an erasure journal:
sqlalchemy-audit-trail/checkpoint/v2
{"block_hash":"<base64>","chain":"<chain id>","incarnation":1,"sealed_at":"<timestamp>","seq":3,"v":1,"xid_to":120}
{"erasure_journal":"<base64>"}
The second line is the version 1 line, with v still 1. The third line is the canonical encoding of an object with exactly the member erasure_journal: base64 of 32 bytes, the SHA-256 commitment of the journal's canonical form, as the canonical encoding specification defines it. A reader MUST refuse a statement whose third line is not exactly that canonical encoding. A checkpoint without a journal is a version 1 statement. A bundle verifier reads a version 2 checkpoint as the version 1 checkpoint of its first two lines: the journal is not in the bundle, and the verifier does not check the commitment. reapply_erasures() checks it against the journal it is given.
An extension line belongs to the application: it is signed with the statement and never interpreted. A writer MUST NOT write a line that does not read as what it says. A line is at most 1024 bytes of UTF-8, and is refused when it:
- is empty, or only whitespace (such as a lone space);
- has a control character (Unicode
Cc), format character (Cf, such as a bidi override), surrogate (Cs), line separator (Zl) or paragraph separator (Zp); - has a private-use (
Co) or unassigned (Cn) code point, in the Unicode version the writer knows; - has U+115F, U+1160, U+3164 or U+FFA0 (the Hangul fillers) or U+2800 (the braille blank), which render as blank space;
- starts with
sqlalchemy-audit-trail/in any case (compared after Unicode case folding), which is reserved for the package.
A reader MUST accept every line 0.5.0 could write, so that its signed notes keep verifying: a line that is non-empty, at most 1024 bytes of UTF-8, with no Cc, Cf, Cs, Zl or Zp character, and that does not start with sqlalchemy-audit-trail/ exactly. A reader MUST refuse any other line as malformed. A checkpoint read with such a line still verifies; only a new checkpoint may not carry one.
A reader accepts every statement version up to its own; a reader of bundle version 1 MUST accept statement versions 1 and 2. A checkpoint whose first line is a statement version the reader does not know is malformed.
Malformed bundles¶
A file that cannot be read as a bundle is an error, not a report: a verifier MUST stop and say so, and MUST NOT report findings for it. The reference verifier raises BundleError, whose message names the entry and line, never a stored value, and its command line exits with 2. A bundle is malformed when:
- it is not a readable zip file, holds an entry twice, does not hold the entries of the layout in order, or holds an entry between
keys.jsonandmanifest.notethat is not a host file; - a line is longer than the limit or does not end in a newline, or a line,
header.jsonorkeys.jsonis not a JSON object; header.jsonhas abundle_versionother than the integer1or2(a reader of version 1 only: other than1;true,2.0and"2"are not versions), astream_typeother than"audit"(or"ledger", which the ledger format spec covers), no textchain, a scope that is not a range of blocks as above, atimethat is notnullor two timestamps, ortablesthat are not a non-empty list of distinct values amongtransactionandactivity;- a block record has a field of the wrong type:
seqnot an integer,kindnot text,body,prev_hashorblock_hashnot base64,sealed_atnot a timestamp,signaturenot base64 ornull,key_idoralgnot text ornull; - the first block record is not block
previous, whenpreviousis notnull; - the chain has no genesis block:
previousisnulland the first block is not a valid genesis block, orblocks.jsonlis empty; - the chain id the blocks give is not the header's
chain; blocks.jsonlholds a block afterlast;- a row record has a field of the wrong type:
seqnot an integer ornull,tablenottransactionoractivity,streamorpartitionnot text,idorxidnot an integer,leafnot text ornull,groupsnot an object of texts ornull,nullsnot an array of the erasable keys above; - a row record's
leafis not a JSON object, names anotheridorxidthan the record, or gives another stream than the record's (transactionfor a transaction row,activity.<severity>of the leaf's integerseverityfor an activity row); for anullleaf, an activity record's stream is notactivity.<integer>; groupsnames a group the table does not have, a group text is not JSON, a row record of a version 1 bundle has thestategroup orstateinnulls, theactorgroup is not an object, a transaction row hasnulls, or an activity row's leaf has nodataobject, or hasactorfields orcontext.*nulls without acontextobject;- a row in
rows.jsonlis of a table the header leaves out, or has anullseq; the rows are not inseqorder; a row names a block that is not a valid seal block inblocks.jsonl; or one partition holds rows of both tables; - a record in
scrubs.jsonlis not an activity row with the verbaudit.scrubbed, or is also inrows.jsonlwith anotherleaf; - a checkpoint record has a
sourceother thangivenandchain, ablockthat is not an integer ornull, anotethat is not text, or a note that is not a checkpoint; keys.jsonhas akey_idsthat is not an array of text, or ahistorythat is not an object ornull;manifest.noteis not a note; its text is not exactly two lines, the firstsqlalchemy-audit-trail/bundle-manifest/v1; the second is not a JSON object with the header'sbundle_version(an integer), the header'schainand afilesarray; or a file is not an object with a textname, a base64sha256and an integersize.
Verification¶
Inputs¶
| Input | Meaning |
|---|---|
| The bundle | A file the verifier can read entries of in any order |
| Trusted keys | Verifier keys trusted to sign blocks, checkpoints and the manifest. Required |
| Trusted checkpoints | Checkpoint notes, possibly unsigned. Default none |
| Key history | {key_id: {valid_from, retired_at, compromised_from}}. Default none |
| Retention | Per severity, a duration or forever, and a duration or forever for the transaction table. Default none |
| System severity | The severity of the audit.scrubbed records. Default none |
| Require signatures | Every block and every checkpoint must be signed by a trusted key. Default off |
| Manifest hash | The SHA-256 of manifest.note, as 64 hex digits, kept or committed elsewhere when the bundle was written. Default none |
A checkpoint given that is not a checkpoint note, and a manifest hash that is not 64 hex digits, are errors of the input, reported before the bundle is read.
The report¶
| Field | Value |
|---|---|
status |
FAILED with any failure; else VALID_WITH_NOTES with any note; else VALID |
anchor |
ANCHORED when a trusted checkpoint matched a block of the bundle; else UNANCHORED |
verified_to |
The seq of the last block record of blocks.jsonl |
failures |
Every failure |
notes |
Every note, acknowledged failures included |
A finding has a kind and a sentence for people (detail), and some of seq, table, partition, stream, id, xid, group, count, root, waived and ack, as the finding table lists. root is the base64 Merkle root rebuilt from the rows. The order of findings, and the wording of detail, are not part of the format. A finding never holds a stored value or a salt.
The reference verifier also returns head, the last block as an unsigned checkpoint statement, or none when the scope does not show its incarnation. It is not part of the format.
Steps¶
A verifier MUST give the report the following steps give, for every bundle that is not malformed. The steps are in the order of the reference verifier, which reads each .jsonl entry once, line by line, and holds one seal block's segment trees at a time; another order that gives the same report is allowed.
- Read
manifest.noteandheader.json. - Read
checkpoints.jsonl. The trusted checkpoints are the checkpoints given, then each checkpoint of the bundle that has a signature line of a trusted key, each once by its note text. Signatures are verified in step 9. - Check the blocks of
blocks.jsonl: resume from the first record whenpreviousis notnull, then check each block. If the last block read is belowlast, fail withTRUNCATED(seq:last). - Read the retire blocks after the scope in
retired.jsonl. - Check the rows of
rows.jsonl, with their groups and their stamps. - Count the scrub records of
scrubs.jsonlthat are not inrows.jsonl. - Take every partition named by a segment in scope whose streams are all of tables the header leaves out as present, neither checked nor missing.
- Hash
keys.jsonand the host files, and check the manifest. - Check the trusted checkpoints.
- Apply the retire blocks after the scope that are vouched for.
- Check the partitions.
- Compare the scrub counts.
- Apply the ack blocks, and set the status.
Resuming from the block before the scope¶
When previous is not null, the first block record, block previous, is the block before the scope. Nothing before it is in the bundle. The verifier:
- Fails with
HASH_MISMATCH(seq:previous) when itsprev_hashis not 32 bytes or itsblock_hashis notSHA-256("sqlalchemy-audit-trail/block/v1" || 0x00 || prev_hash || body). - Parses its body. When the body is not a JSON object with
v1, itskindequal to the block's, itsseqequal to the block's and a textchain, it fails withMALFORMED_BLOCK(seq:previous); the incarnation is then not known, its xid space is not known, the first seal block in scope sets where sealing starts, and the first block in scope that names a chain gives the chain id. -
Otherwise takes the chain id from its
chain, and starts the current incarnation from it:- a
genesisblock: incarnation 1, sealed up to itsenforce_from; - a
sealorcheckpointblock: an incarnation whose number is not known, sealed up to itsxid_to; - a
forkblock: the incarnation of itsincarnationmember, in a new xid space, sealed up to itsxid_at_fork, with its id window (id_floorandid_count, when valid); - any other kind: an incarnation whose number is not known, with an open start: the first seal block in scope sets where it is sealed up to.
A horizon member that is not an integer also gives an open start, and a fork's
incarnationthat is not an integer an incarnation whose number is not known. 4. Records it as a block a fork may name as its prior checkpoint when it is agenesis,checkpointorforkblock, and as a fork that may explain a checkpoint when it is a fork block of incarnation 2 or more with an integerprior_checkpoint.seq. 5. Checks its signature as for any block. - a
The block before the scope counts as held by the bundle: a trusted checkpoint may name it.
The chain¶
The blocks in scope are numbered from previous + 1, or from 1 when previous is null. For each block record, in order, with number its expected number:
- Link. Fail with
PREV_MISMATCH(seq) whenprev_hashis not theblock_hashof the block before (32 zero bytes for block 1). - Hash. Fail with
HASH_MISMATCH(seq) whenprev_hashis not 32 bytes orblock_hashis not the hash ofprev_hashandbody. - Signature. With no
signature,key_idandalgat all: fail withBAD_SIGNATUREwhen signatures are required. With only some of them: fail withBAD_SIGNATURE. Signed by a key the verifier does not trust: fail withUNKNOWN_KEY. Whenalgis not the trusted key's algorithm, or the signature does not verify over the block signature message: fail withBAD_SIGNATURE. When it verifies but the key history puts it outside its window atseq: fail withKEY_NOT_VALIDorKEY_COMPROMISED. Otherwise the block is signed by a trusted key. Every finding of this step hasseq. - Body. Fail with
MALFORMED_BLOCK(seq) and read nothing more of the block when: the body is not a JSON object;seqis notnumberor the body'sseqis notseq; the body'svis not1; the body'skindis notkind; for block 1, it is not agenesisblock with an integerenforce_fromand a textchain; for any other block, itschainis not the chain id. Whenpreviousisnull, block 1, valid, gives the chain id and starts incarnation 1, sealed up toenforce_from; it may be named as a prior checkpoint. When it is not valid, the bundle is malformed. - Kind. Read the block as its kind says, below. Any kind not listed,
genesisafter block 1 included, fails withMALFORMED_BLOCK.
The block_hash of every block, valid or not, is the link the next block is checked against.
seal. Its xid_from and xid_to MUST be integers with xid_from < xid_to. When the incarnation has an open start and no seal block yet, xid_from sets where it is sealed up to. xid_from MUST equal where the current incarnation is sealed up to: the xid_to of its last seal block, or where it started. segments MUST be an array of objects, each with a text stream, a text partition, an integer rows above 0 and a root that is base64 of 32 bytes, with no two of the same stream and partition. Otherwise it fails with MALFORMED_BLOCK. A valid seal block becomes the current incarnation's last, and its segments are the expected segments of their partitions.
ack. Its failure MUST name a failure an ack may waive: ROOT_MISMATCH, ROW_COUNT_MISMATCH, COMMITMENT_MISMATCH, COMMITMENT_MISSING, ERASURE_UNEXPLAINED, SCRUB_COUNT_MISMATCH, SEGMENT_MISSING, RETIRED_EARLY or DETACHED_PARTITION. Its scope MUST be a non-empty object whose keys are among table, partition, stream, group (text) and seq, id, xid, xid_from, xid_to, id_from, id_to (integers), and not table alone. Its waives MUST be a non-empty array of non-empty objects whose keys are among seq, table, partition, stream, id, xid, group, count and root, with table, partition, stream, group and root text and the others integers. Otherwise it fails with MALFORMED_BLOCK. A valid ack block is used in acknowledgements.
checkpoint. Its xid_to MUST be an integer. When the body has a note member, the block records a checkpoint (record_checkpoint): the note MUST be a checkpoint of this chain naming a block before this one, and either a block of blocks.jsonl (the block before the scope included), with that block's hash, or a block before the block before the scope, which is noted as OUT_OF_SCOPE (seq: this block). Otherwise it fails with MALFORMED_BLOCK. The recorded note's signatures are not checked here: the copy in checkpoints.jsonl (source "chain") is a trusted checkpoint only when a trusted key signed it, and is then checked like any other. The checkpoint block, and the block of blocks.jsonl a recorded checkpoint names, may be named as a prior checkpoint.
fork. Its incarnation MUST be an integer of at least 2, one more than the current incarnation when that is known; its reason text; its xid_at_fork an integer of at least 0; its prior_checkpoint an object with an integer seq and a block_hash that is base64 of 32 bytes, naming either a block that may be named as a prior checkpoint, with its hash, or a block before the block before the scope. id_floor and id_count MUST both be null, or both objects with the same keys, each a stream, and values integers of at least 0. A fork without an id window MUST NOT start below where the current incarnation is sealed up to, unless that is not known. Otherwise it fails with MALFORMED_BLOCK. A valid fork block:
- starts the next incarnation, sealed up to
xid_at_fork. Without an id window it stays in the current xid space and keeps the current id floor. With one, every incarnation of the current xid space is capped atid_floor(a row of a stream with anidabove the floor, or of a stream the floor does not name, is not theirs), and the new incarnation holds the rows above the floor, in a new xid space; - notes
FORKED(seq); - notes
OUT_OF_SCOPE(seq) when its prior checkpoint is before the block before the scope, whose hash is then not checked; - notes
FORKED_UNSIGNED(seq) when it is not signed by a trusted key. Such a fork explains no checkpoint.
retire. Its table MUST be transaction or activity, its partition text, its streams a non-empty array of streams of that table, and its upper_bound a timestamp; the partition MUST not have been retired by an earlier retire block. Its coverage MUST match the expected segments of its partition so far, and their streams MUST be among streams:
- when its
seals.firstis at or before the block before the scope, it also covers segments outside the scope:segments_digestMUST be text and, when there are expected segments,seals.firstat or before the first of them,seals.lastequal to the last of them,segmentsat least their number androwsat least their rows together. It is noted asOUT_OF_SCOPE(seq,partition); - otherwise its
seals,segments,rowsandsegments_digestMUST equal the retire digest of the expected segments of its partition, as the canonical encoding spec defines it.
Otherwise it fails with MALFORMED_BLOCK, and retires nothing. A valid retire block retires its partition: it covers the expected segments of the partition at that point, and is checked against retention.
Retire blocks after the scope¶
Each block record of retired.jsonl:
- Fails with
HASH_MISMATCH(seq) when its hash does not match itsprev_hashand body, and is then skipped. - Fails with
MALFORMED_BLOCK(seq), and is skipped, unless its body parses withv1, itskindand the record'skindare bothretire, itsseqis the record's, itschainis the chain id, itsseqis after the last block ofblocks.jsonland not that of an earlier record, itstable,partition,streamsandupper_boundare valid as for a retire block in scope, and its partition was not retired in scope. - Fails with
MALFORMED_BLOCK(seq), and is skipped, unless its coverage fits the expected segments of its partition in scope as for a retire block that also covers segments outside the scope, except thatseals.lastMAY be after the last of them; and their streams are amongstreams. - Has its signature checked as a block's.
Such a block is a candidate. After the checkpoints are checked (step 10), each candidate, in seq order, is vouched for when a trusted checkpoint names it with its hash or it is signed by a trusted key. A vouched-for candidate retires its partition, unless it is already retired, covering the expected segments of the partition in scope, and is checked against retention. A candidate not vouched for is noted as OUT_OF_SCOPE (seq, partition) and explains nothing.
Retention¶
Given a retention, each stream has a limit: an activity stream the limit of its severity; the transaction stream the transaction limit capped at the shortest finite severity limit, or that shortest limit when the transaction limit is forever, or the transaction limit when no severity limit is finite. A retire block fails with RETIRED_EARLY (seq, table, stream, partition) for the first of its streams, in order, that has a limit and whose limit is forever or ends after the block: its upper_bound is after its sealed_at minus the limit. It fails at most once. A stream without a limit is not checked. sealed_at is not hashed, so this check trusts the bundle's sealed_at.
Rows, leaves and segment roots¶
Each row record gives a row as the verifier checks it:
- With a
nullleaf, the row's leaf hash is 32 zero bytes, which matches no sealed leaf, and its groups are not checked: it has emptyseal_commitments. - Otherwise the leaf hash is over the UTF-8 bytes of
leaf, and the row's columns are rebuilt from the leaf row,groupsandnulls:- a transaction row's
actor_label,remote_addr,user_agentandmetaare the fields of theactorgroup,nullwhen absent; - an activity row's
object_labelis thelabelgroup,nullwhen absent;data.changes,data.payloadanddata.stateare their groups, ornullwhen the key is innulls, or absent; the fields of theactorgroup are set indata.context, and eachcontext.<field>ofnullsis set tonullthere; seal_commitmentscomes from the leaf row, andseal_saltsandseal_erasedaresaltsanderased.
- a transaction row's
- With a
nullgroups, the row's values are unreadable.
The rows are given in seq order. For each row, the verifier adds its leaf hash to the tree of its segment (seq, stream) in its partition, counts its stamps and keeps it when it is a scrub record, and checks its groups. When the seq changes, the trees of every partition with an earlier seq are finished. At the end every tree is finished, and every partition with a row is present.
Finishing a tree compares it with the expected segment of its (seq, stream) in its partition, or with zero rows when there is none:
- with another number of leaves: fail with
ROW_COUNT_MISMATCH; - with the same number but another Merkle root: fail with
ROOT_MISMATCH.
Both have seq, stream, partition, table, count (the leaves in the bundle) and root (their Merkle root, base64). At the end, every expected segment of a present partition with no tree fails with ROW_COUNT_MISMATCH with count 0 and the root of no leaves, SHA-256("").
Commitments and erasures¶
For a row that is sealed, with seal_commitments null: fail with COMMITMENT_MISSING (seq, table, partition, id, xid), and check nothing more of the row. With unreadable values: fail with COMMITMENT_MISMATCH with no group. Otherwise, with commitments, salts and stamps the row's seal_commitments, seal_salts and seal_erased (null read as {}):
- If any of the three is not an object: fail with
COMMITMENT_MISMATCHwith nogroup, and stop. - Compute the value of each group of the table as the canonical encoding spec defines it. If a value cannot be computed (an activity row's
datais not an object, or a transaction row'sremote_addris not an address in the strict form the spec accepts): fail withCOMMITMENT_MISMATCHwith nogroup, and stop. - For each group of the table, in order (
label,changes,payload,state,actor; oractor):- If the group is
stateand the row'sdatahas the keystatewith the valuenull: fail withCOMMITMENT_MISMATCH, and go on to the next group. No writer stores it and no scrub leaves it, so a nullstatewas put there, and it is committed to nothing. - Else, if
saltshas the group: the salt MUST be base64 of 16 bytes,commitmentsMUST have the group as base64 of 32 bytes, the value MUST NOT benull, and the commitment of the group, salt and value MUST equal it. Otherwise fail withCOMMITMENT_MISMATCH. - Else, if
stampshas the group: the stamp MUST name a scrub, and the group MUST be in erased form. Otherwise fail withERASURE_UNEXPLAINED. The group is erased when it also has a commitment. - Else, if
commitmentshas the group: fail withERASURE_UNEXPLAINED: the salt was removed without a stamp. - Else, if the value is not
null: fail withCOMMITMENT_MISMATCH: a value without a commitment.
- If the group is
- For each key of
commitments,saltsorstampsthat is not a group of the table, sorted: fail withCOMMITMENT_MISMATCHfor that group.
Every finding of these steps has seq, table, partition, id, xid and, where there is one, group. A row with an erased group counts once in its partition's ERASED note: when a partition has such rows, note ERASED (table, partition, count).
A stamp names a scrub when it is an integer, or text of ASCII digits; that number is the scrub's xid.
Erased form¶
A group is in erased form when it holds what a scrub leaves:
- a transaction row's
actor: the four actor columns are allnull; - an activity row with a
datathat is not an object: no group is in erased form; label:object_labelisnull;- an activity row's
actor:data.contextis absent ornull, or an object with none of the keysactor_label,remote_addr,user_agentandmeta; changesandpayload: the key is absent fromdata; orchangesis an object each of whose values is erased, where an array is erased when each element isnullor"[erased]", an object when each value is an erased array ornullor"[erased]", and anything else when it isnullor"[erased]"; orpayloadis an object each of whose values isnullor"[erased]"; or the value is the string"[erased]".state: aspayload: the key is absent fromdata; orstateis an object each of whose values isnullor"[erased]"; or the value is the string"[erased]".
A key stored as null (listed in nulls) is present, so changes, payload or state stored as null is not in erased form.
Scrub records and stamps¶
Incarnations and xid spaces. Each row belongs to an incarnation: of the incarnations whose id window holds the row's id for its stream, the first, or a later one of the same xid space that starts at or below the row's xid. A row of rows.jsonl belongs to the incarnation of its seal block. A fork with an id window starts a new xid space; one without stays in the current one. The current space is that of the last incarnation. The limit of a space is 264 for the current space, and for an earlier one the highest xid its incarnations are sealed up to.
Stamps. A stamp that does not name a scrub is not counted. Each stamp of a row in rows.jsonl that names a scrub with xid s, for a row with xid r in space S, is counted for (table, group, space, s):
- in
S, whenr ≤ sandsis below the limit ofS; - in the current space, when
Sis an earlier space andsis at or above the firstxidof the current space and below 264; - as shared between
Sand the current space when both hold.
When neither holds, fail with SCRUB_COUNT_MISMATCH (table, partition, id, xid, group): the stamp names a scrub older than its row, or in the future.
Records. A scrub record is an activity row with the verb audit.scrubbed. Each one in rows.jsonl is counted in the space of its incarnation. Each one in scrubs.jsonl that is not in rows.jsonl (by id) is counted in the space of its incarnation, unless the scope starts at block 1 and the record belongs to no incarnation or is below where its incarnation starts; and each one is noted as OUT_OF_SCOPE (seq, table, partition, id, xid), since it is not checked against a root. A record's data.payload says how many rows it stamped:
"operation": "scrub":stamped_activity_rows, oractivity_rowswhen that is absent, for each of the activity groupslabel,changesandpayload; andstamped_state_rows, or 0 when that is absent, for the activity groupstate(a scrub stampsstateonly on the rows that havedata.state);"operation": "scrub_actor":stamped_activity_rows(oractivity_rows) for the activityactorgroup, andstamped_transaction_rows(ortransaction_rows) for the transactionactorgroup.
Other members of the payload, such as uncommitted (the rows the scrub erased that carry no commitments, which it could not stamp), are not read. A record whose payload is not an object, names another operation, or whose count is not an integer of at least 0, fails with SCRUB_COUNT_MISMATCH (table, partition, id, xid).
Comparing. For each (table, group, xid) that a record or a stamp names, and each space it is counted in, want is the rows the records recorded and have the stamps. Shared stamps go to the space whose records accept them. Each space accepts from lo to hi stamps: from max(want − gone, 0) to want, where gone is its retired rows, or from 0 to any number when no record of the scrub was seen in it and its receipt was retired. Of the pool stamps shared between an earlier space E and the current one, E takes at least least(E) = min(max(lo(E) − have(E), 0), pool) and at most most(E) = min(max(hi(E) − have(E), 0), pool), or pool when hi(E) is unbounded. The earlier spaces take T = min(max(have(current) + Σpool − lo(current), Σleast), Σmost) stamps together: each its least, and the rest of T from the lowest space up, each to its most. The current space gets the other Σpool − T. Then, for each space:
wantequalshave: nothing.- No record of the scrub was seen in that space and its receipt was retired: note
ERASED_RECEIPT_RETIRED(table,xid,group,count:have). haveis belowwantby at mostgone: noteSCRUBBED_ROWS_RETIRED(table,xid,group,count:have): the other rows may have left with retired partitions.haveis belowwant: noteOUT_OF_SCOPE(table,xid,group,count:have): the other rows may be outside the scope.- Otherwise: fail with
SCRUB_COUNT_MISMATCH(table,xid,group,count:have).
Retired rows¶
The retired rows of the scrub at xid in space S, for a table, are the rows the scrub may have stamped that are gone with their partitions: the sum of rows of each expected segment covered by a retire block (in scope, or a vouched-for one after it) whose table is that table and whose partition is neither present nor taken as present, when the segment's seal block belongs to an incarnation of another space than S, or its xid_from is below xid. A stamp names a scrub after its row, so a segment sealed from xid on in S holds no row the scrub stamped. Retire blocks carry no stamp counts, so this bounds what a retired partition can explain by its rows.
Retired receipts¶
The receipt of the scrub at xid in a space was retired when the system severity is given, a seal block of an incarnation of that space covers xid in its range, and a partition that is neither present nor taken as present was retired (in scope, or by a vouched-for retire block after it) with the system severity's stream among its streams and that seal block's segment of that stream among the segments it covers.
Partitions¶
After the checkpoints (step 11), for each partition named by an expected segment, in name order, that is neither present nor taken as present (step 7):
- let
Rbe the retire block that retired it, if any, and the missing segments its expected segments thatRdoes not cover (all of them withoutR); - when
Rcovers at least one segment, noteRETIRED(seq:R,table,streamwhenRnames one stream,partition,count: the segments covered); - when segments are missing, fail with
SEGMENT_MISSING(seqandstreamof the first missing segment byseq,partition,count: the missing segments).
Checkpoints and trust¶
For each trusted checkpoint, in order:
- When it names a block the bundle does not hold, note
OUT_OF_SCOPE(seq: the block it names) and do not use it. The bundle holds the block before the scope, the blocks in scope, and the retire blocks after the scope that passed the checks above. - When signatures are required and it is unsigned: fail with
BAD_SIGNATURE(seq) and do not use it. - When it is signed: verify the note with the trusted keys. Unknown key: fail with
UNKNOWN_KEY(seq); bad signature or malformed: fail withBAD_SIGNATURE(seq); in either case do not use it. When a key that verified is outside its window at the checkpoint'sseq, fail withKEY_NOT_VALIDorKEY_COMPROMISED(seq) and do not use it. - When its
chainis not the chain id: fail withCHAIN_MISMATCH(seq). - When it names a retire block after the scope: with that block's hash it vouches for the block; with another, fail with
CHAIN_MISMATCH(seq). - When it names a block of
blocks.jsonlwith its hash: when the incarnation of that block is known and is not the checkpoint'sincarnation, fail withCHAIN_MISMATCH(seq); otherwise it matches. - Otherwise its block has another hash (
CHAIN_MISMATCH), or no block record has itsseq(TRUNCATED). When a fork block that is signed by a trusted key starts a later incarnation than the checkpoint's and names a prior checkpoint below the checkpoint'sseq, noteFORKED(seq): the fork explains it. Otherwise fail with that kind (seq).
The report is ANCHORED when a checkpoint matches. When the last block read is after the newest checkpoint that matches, note UNANCHORED_TAIL (seq: one after that checkpoint's, count: the blocks after it).
An unsigned checkpoint given is used, unless signatures are required: the caller vouches for it. An unsigned checkpoint in the bundle is never used, and neither is one signed only by keys the verifier does not trust.
Key history windows¶
A key history gives each key a window: valid_from (the first seq it may sign, default 1), retired_at (the first seq it may no longer sign, or null) and compromised_from (the first seq from which its signatures are not trusted, or null). A signature at position p that verifies is outside the window when:
- the key has no window:
KEY_NOT_VALID; compromised_fromis notnullandp ≥ compromised_from:KEY_COMPROMISED;p < valid_from, orretired_atis notnullandp ≥ retired_at:KEY_NOT_VALID.
The position is the block's seq for a block signature, the seq the checkpoint names for a checkpoint signature, and the scope's last for the manifest. A signature outside its window counts as none: the block is not signed by a trusted key, the checkpoint is not used, the manifest is not anchored by it.
The manifest and its anchors¶
The verifier compares the manifest's files with the entries other than manifest.note, by the SHA-256 and size of the bytes read:
- a file listed that the bundle does not hold: fail with
MANIFEST_MISMATCH; - a file listed whose SHA-256 or size is not the entry's: fail with
MANIFEST_MISMATCH; - an entry the manifest does not list: fail with
MANIFEST_MISMATCH; - the listed entries in another order than in the zip: fail with
MANIFEST_MISMATCH, once.
The manifest is anchored when either holds:
- A trusted signature. It has a signature line of a key the verifier trusts, the note verifies, and at least one key that verified is inside its window at
last. An unsigned manifest, or one signed only by unknown keys, is not anchored by this, with no finding. A note that fails with bad signature, or is malformed, fails withBAD_SIGNATURE. A key outside its window fails withKEY_NOT_VALIDorKEY_COMPROMISED(seq:last). - A manifest hash. A manifest hash is given and equals the SHA-256 of the bytes of
manifest.note. A manifest hash given that is not equal fails withMANIFEST_MISMATCH.
When the manifest is not anchored, each host file is noted as UNANCHORED: anyone who can write the bundle can change a host file and the manifest together. The other entries need no anchor: everything in them that the verification relies on is checked against the chain.
Acknowledgements¶
Each failure of a kind an ack may waive is waived by a valid ack block in scope when the failure is of the ack's failure, matches its scope, and its pin is among the ack's waives:
- A failure matches a scope when it has every field the scope names, with that value;
xid_fromandid_fromare inclusive lower bounds ofxidandid, andxid_toandid_toexclusive upper bounds. - The pin of a
COMMITMENT_MISMATCH,COMMITMENT_MISSINGorERASURE_UNEXPLAINEDis itstable,idandgroup; of any other kind itsseq,table,partition,stream,id,xid,group,countandroot; in both cases only the fields that are notnull. Two pins are equal when they have the same fields with the same values.
A waived failure is reported as an ACKNOWLEDGED note with the failure's fields, waived (its kind) and ack (the ack block's seq), instead of the failure. A failure that changed since the ack was written has another pin, and is reported again.
Findings¶
Every kind a bundle verifier reports, with when it is raised and the fields it has. Failures make the status FAILED; notes make it VALID_WITH_NOTES when there is no failure.
| Kind | Failure or note | Raised when | Fields |
|---|---|---|---|
PREV_MISMATCH |
Failure | A block's prev_hash is not the hash of the block before |
seq |
HASH_MISMATCH |
Failure | A block's block_hash is not the hash of its prev_hash and body (the block before the scope and retire blocks after it included) |
seq |
MALFORMED_BLOCK |
Failure | A block's body does not parse as a block of its kind, number and chain, or does not match the chain before it | seq |
TRUNCATED |
Failure | blocks.jsonl ends before last |
seq (last) |
CHAIN_MISMATCH |
Failure | A trusted checkpoint is of another chain, or names a block of the bundle with another hash or incarnation, and no signed fork explains it | seq |
BAD_SIGNATURE |
Failure | A signature of a trusted key does not verify, a block's signature is partial, or a block or checkpoint is unsigned when signatures are required | seq, none for the manifest |
UNKNOWN_KEY |
Failure | A block, or a checkpoint given, is signed only by keys the verifier does not trust | seq |
KEY_NOT_VALID |
Failure | A signature verifies by a key outside its window, or with no window, in the key history | seq |
KEY_COMPROMISED |
Failure | A signature verifies by a key at or after its compromised_from |
seq |
ROOT_MISMATCH |
Failure | The rows of a segment give another Merkle root | seq, table, partition, stream, count, root |
ROW_COUNT_MISMATCH |
Failure | A segment has another number of rows in the bundle, or rows with no segment | seq, table, partition, stream, count, root |
SEGMENT_MISSING |
Failure | A partition named by segments has no row in the bundle and no retire block covers them | seq, partition, stream, count |
RETIRED_EARLY |
Failure | Given a retention, a partition was retired while still inside it | seq, table, partition, stream |
COMMITMENT_MISMATCH |
Failure | An erasable value does not match its commitment, has none, or cannot be read | seq, table, partition, id, xid, group |
COMMITMENT_MISSING |
Failure | A sealed row has no commitments | seq, table, partition, id, xid |
ERASURE_UNEXPLAINED |
Failure | A salt is gone without a stamp, or a stamped group is not in erased form | seq, table, partition, id, xid, group |
SCRUB_COUNT_MISMATCH |
Failure | More rows carry a scrub's stamp than its records recorded, a stamp names a scrub older than its row or in the future, or a record has no known operation and counts | table, xid, group, count; for one stamp table, partition, id, xid, group; for one record table, partition, id, xid |
MANIFEST_MISMATCH |
Failure | An entry does not match the manifest, or the manifest's hash is not the one given | none |
ERASED |
Note | A partition has rows with erased groups | table, partition, count |
ERASED_RECEIPT_RETIRED |
Note | Rows carry the stamp of a scrub whose record was sealed in a partition since retired | table, xid, group, count |
SCRUBBED_ROWS_RETIRED |
Note | Fewer rows carry a scrub's stamp than its records recorded, by at most the rows that left with retired partitions | table, xid, group, count |
RETIRED |
Note | A partition with no row in the bundle was retired by a retire block that covers its segments | seq, table, partition, stream, count |
UNANCHORED_TAIL |
Note | Blocks come after the newest checkpoint that matched | seq, count |
FORKED |
Note | A fork block starts an incarnation, or a signed fork explains a checkpoint | seq |
FORKED_UNSIGNED |
Note | A fork block is not signed by a trusted key | seq |
ACKNOWLEDGED |
Note | An ack block waives a failure | The failure's fields, waived, ack |
OUT_OF_SCOPE |
Note | A trusted checkpoint names a block the bundle does not hold; a scrub record is sealed outside the scope, or not yet; fewer rows in scope carry a scrub's stamp than its records recorded, by more than retired partitions explain; a fork, retire or recorded checkpoint block names a block before the block before the scope; a retire block after the scope is not vouched for | As the step that raises it |
UNANCHORED |
Note | A host file is under a manifest that is not anchored | none |
What a bundle verifier cannot check¶
A bundle holds no live database, so a bundle verifier MUST NOT report:
DETACHED_PARTITION: a detached partition's rows are not in the bundle, so its segments areSEGMENT_MISSING;UNSEALED_TAIL: rows not yet sealed are not in the bundle, and every scrub has finished;XID_REWINDagainst the live horizon of the database, and rows from the future;PRE_GENESIS: every row of a bundle is sealed by a block in scope.
There is no live horizon: a bundle verifier takes every scrub as finished. The reference verifier uses 264, above every xid, as both the horizon and the xmax. A consequence, outside this format: a forged block whose sealed horizon is above 264, which no PostgreSQL xid8 can reach, is reported by the reference verifier as XID_REWIND. Other verifiers need not report it, and no vector covers it.
The bundle cannot show either:
- that its blocks were written in the header's time range, or when it was written:
sealed_atand the header are not hashed; - that a retire block was written after its partition's retention ran out:
RETIRED_EARLYcompares withsealed_at, which is not hashed; - rows of a block before the scope, or the chain before the block before the scope;
- that it is the real chain, without a trusted checkpoint or trusted block signatures.
Stability¶
Bundle version 1 does not change within the 0.x minor releases after the one it ships in: a bundle written by one of them is read by every later one, with the same report. A change to the layout, a field or the verification rules gets a new bundle_version. A verifier that reads a version MUST also read the versions before it, for at least one minor release after the new one ships. A verifier MUST refuse a bundle whose bundle_version it does not know.
Versions 1 and 2¶
Version 2, from 0.8.0, adds the state group and the state key of nulls, and the stamped_state_rows count of a scrub record; the layout, the manifest header and every other rule are version 1's. A writer writes version 2 only for an export with a state row in scope, so every other bundle stays version 1 and every version 1 reader reads it as before. A version 1 reader given a version 2 bundle refuses it as malformed (the reference verifier of 0.7: bundle version 2 is not supported, exit code 2); it never reports on it. A version 2 reader reads both, and a version 1 bundle that holds state is malformed. A ledger bundle is always version 1.
A change to the canonical encoding or to a hash preimage gets a new domain tag, never other bytes for an existing one. New checkpoint statement versions do not change the bundle version: a reader accepts every statement version up to its own.
Reference command line¶
The command line python -m audit_trail.integrity verify-bundle FILE --keys KEYFILE runs the reference verifier, with --checkpoint, --key-history, --retention SEV=DAYS (repeatable; DAYS may be KEEP, forever), --transaction-retention DAYS, --manifest-sha256, --system-severity, --require-signatures, --require-anchor and --json. It exits with 0 for VALID and VALID_WITH_NOTES, 1 for FAILED (or not anchored with --require-anchor), and 2 for a malformed bundle or input. --json prints the report as a JSON object with status, anchor, verified_to, failures and notes, each finding with its fields that are not null. This section is informative.
Test vectors¶
The vectors are under docs/spec/vectors/bundle/. Each is a bundle, <name>.zip, and a JSON file, <name>.json:
| Field | Value |
|---|---|
description |
What the vector holds |
bundle |
The bundle's file name |
options |
The inputs: keys (verifier keys), checkpoints (notes), key_history (as in keys.json, or null), retention (severity as text to seconds or null for forever, or null for none), transaction_retention (seconds or null), system_severity, require_signatures and manifest_sha256 |
expected |
status, anchor, verified_to, failures and notes, each finding with its kind and its fields that are not null, without detail; or {"malformed": true} for a bundle a verifier MUST refuse as malformed, without a report |
A verifier passes a vector when it gives the same status, anchor and verified_to, and the same failures and notes in any order. The keys are Ed25519 keys from fixed seeds, the salts fixed, the timestamps fixed and the zip entries stored (except one deflated entry in valid-deflated, whose compressed bytes may differ with another zlib build while its contents do not), so the files are rebuilt byte for byte by tests/unit/bundle_vectors.py (uv run python -m tests.unit.bundle_vectors); a test fails when the files differ from what it builds, when a vector does not give its expected report, or when a finding kind a bundle verifier reports has no vector.
| Vector | Shows |
|---|---|
valid |
VALID, ANCHORED: every block signed, signatures required, a trusted checkpoint in checkpoints.jsonl, a host file under a manifest signed by a trusted key |
valid-range |
VALID: a scope of one block, resumed from the block before it |
valid-deflated |
VALID: as valid-range, with rows.jsonl deflated |
tables-activity |
VALID: the activity table only; the transaction partition is taken as present |
state |
VALID: bundle version 2, an activity row with the state group |
state-erased |
ERASED: bundle version 2, the state scrubbed and stamped, counted by the record's stamped_state_rows |
state-scrub-count-mismatch |
SCRUB_COUNT_MISMATCH (group state), ERASED: a state stamp the record does not count |
state-mismatch |
COMMITMENT_MISMATCH (group state): a state that is not the one committed to |
state-version-1 |
Malformed: a version 1 bundle with the state group |
manifest-sha256 |
VALID: a host file under an unsigned manifest, anchored by the manifest hash given |
manifest-sha256-mismatch |
MANIFEST_MISMATCH, UNANCHORED: a manifest hash given that is not the manifest's |
prev-mismatch |
PREV_MISMATCH |
hash-mismatch |
HASH_MISMATCH |
malformed-block |
MALFORMED_BLOCK: a seal block that does not start where the last one ended |
truncated |
TRUNCATED |
chain-mismatch |
CHAIN_MISMATCH: a trusted checkpoint with another hash |
bad-signature |
BAD_SIGNATURE |
unknown-key |
UNKNOWN_KEY |
key-not-valid |
KEY_NOT_VALID |
key-compromised |
KEY_COMPROMISED |
root-mismatch |
ROOT_MISMATCH: a changed leaf |
row-count-mismatch |
ROW_COUNT_MISMATCH: a missing row |
segment-missing |
SEGMENT_MISSING: a partition gone without a retire block |
commitment-mismatch |
COMMITMENT_MISMATCH: a changed group |
commitment-missing |
COMMITMENT_MISSING |
erasure-unexplained |
ERASURE_UNEXPLAINED: a salt removed without a stamp |
erased |
ERASED: a scrubbed row and its record |
scrub-count-mismatch |
SCRUB_COUNT_MISMATCH, ERASED: a record that counts fewer rows than carry its stamp |
erased-receipt-retired |
ERASED_RECEIPT_RETIRED, RETIRED, ERASED: the record's partition retired |
scrubbed-rows-retired |
SCRUBBED_ROWS_RETIRED, RETIRED, ERASED: a scrub's record counts a row of a partition since retired |
out-of-scope |
OUT_OF_SCOPE, ERASED: a scrub record sealed after the scope, and a checkpoint of a block the bundle does not hold |
retired |
RETIRED |
retired-early |
RETIRED_EARLY, RETIRED |
forked |
FORKED: a signed fork block |
forked-unsigned |
FORKED_UNSIGNED, FORKED |
acknowledged |
ACKNOWLEDGED: an ack block waiving a ROW_COUNT_MISMATCH |
unanchored-tail |
UNANCHORED_TAIL |
recorded-checkpoint-before-scope |
ANCHORED, UNANCHORED_TAIL: a scope that starts at a checkpoint block recording a checkpoint, signed by a trusted key, of the block before the scope; the note is also in checkpoints.jsonl with source "chain" |
recorded-checkpoint-v2 |
ANCHORED, UNANCHORED_TAIL: a checkpoint block recording a version 2 checkpoint of the block before it, signed by a trusted key, that commits to an erasure journal the bundle does not hold; the note is also in checkpoints.jsonl with source "chain" |
unanchored |
UNANCHORED: a host file under an unsigned manifest |
manifest-mismatch |
MANIFEST_MISMATCH: a host file changed after a signed manifest |