Row-level ownership, so a shared schema can have per-row owners.
skuld.ledger.authz scopes writes by the attribute's namespace: a key owns
:<its-hex>/anything. That is self-evident from the attribute alone — no
lookup, no registry, no allocation — and it is the right answer for data
whose SHAPE belongs to its owner: a profile, a note, a document.
It cannot express a shared schema. Every user posting to a ledger writes the
same :kontor.transaction/narration, and under attribute-namespace scoping
that is a system attribute, so an ordinary key is refused. Measured: an
unmodified kontor.book/entry-tx-data posting had ALL 20 of its datoms
refused. A ledger nobody can post to is not a ledger.
So ownership moves onto the ROW: an entity carries :urd/owner, and writing
a system attribute on it requires being that owner.
Storing the 64-character hex on every entity works and is the obvious encoding. It is the wrong one, for a reason that only shows up under key rotation.
Rotating a key that owns 300 rows:
owner as a ref to a key entity 3 datoms, cost 1,415
owner as a hex string on each row 601 datoms, cost 84,537
The ref is O(1) in rows owned; the string is O(rows). And encoding the key
in the ATTRIBUTE NAMESPACE — the first design — is worse than either: the
attribute keyword itself changes, so rotation rewrites every datom under a
new attribute and breaks every external reference to :<oldkey>/foo. That
is a migration, not a transaction.
The ref is also cheaper per write: ~103 against ~164 per entity, since a reference is an integer and the hex is 64 bytes.
Requiring the client to mark every entity it creates is invasive and, for an
existing library, impossible: kontor's builder emits four entities per
posting and knows nothing about urd. stamp adds the owner at the boundary
instead. It is a deterministic function of the signed tx-data, so every
validator derives the same stamped transaction — the signature covers what
the client sent, and the stamp is part of applying it.
:urd/owner is itself a system attribute, so the rule "writing a system
attribute requires owning the row" already means only the current owner can
change it. Transfer falls out; theft does not.
Row-level ownership, so a shared schema can have per-row owners.
## Why attribute namespaces are not enough
`skuld.ledger.authz` scopes writes by the attribute's namespace: a key owns
`:<its-hex>/anything`. That is self-evident from the attribute alone — no
lookup, no registry, no allocation — and it is the right answer for data
whose SHAPE belongs to its owner: a profile, a note, a document.
It cannot express a shared schema. Every user posting to a ledger writes the
same `:kontor.transaction/narration`, and under attribute-namespace scoping
that is a system attribute, so an ordinary key is refused. Measured: an
unmodified `kontor.book/entry-tx-data` posting had ALL 20 of its datoms
refused. A ledger nobody can post to is not a ledger.
So ownership moves onto the ROW: an entity carries `:urd/owner`, and writing
a system attribute on it requires being that owner.
## Why the owner is a ref and not the key itself
Storing the 64-character hex on every entity works and is the obvious
encoding. It is the wrong one, for a reason that only shows up under key
rotation.
Rotating a key that owns 300 rows:
owner as a ref to a key entity 3 datoms, cost 1,415
owner as a hex string on each row 601 datoms, cost 84,537
The ref is O(1) in rows owned; the string is O(rows). And encoding the key
in the ATTRIBUTE NAMESPACE — the first design — is worse than either: the
attribute keyword itself changes, so rotation rewrites every datom under a
new attribute and breaks every external reference to `:<oldkey>/foo`. That
is a migration, not a transaction.
The ref is also cheaper per write: ~103 against ~164 per entity, since a
reference is an integer and the hex is 64 bytes.
## Why the boundary stamps ownership, not the client
Requiring the client to mark every entity it creates is invasive and, for an
existing library, impossible: kontor's builder emits four entities per
posting and knows nothing about urd. `stamp` adds the owner at the boundary
instead. It is a deterministic function of the signed tx-data, so every
validator derives the same stamped transaction — the signature covers what
the client sent, and the stamp is part of applying it.
## Transfer is not a special case
`:urd/owner` is itself a system attribute, so the rule "writing a system
attribute requires owning the row" already means only the current owner can
change it. Transfer falls out; theft does not.(existing? db e)Does e already exist in db?
False for a tempid -- a negative number, a string, or a tx alias. Handing
one to datahike raises :entity-id/syntax rather than returning false, so
this cannot be written as a bare lookup.
It also cannot be written as a bare NUMBER check, which is what it was. A
lookup ref ([:some/unique "x"]) and a :db/ident keyword both name rows
that already exist, and both read as "new" under a number? test -- so
stamp claimed ownership of them, the land grab this predicate exists to
prevent. The visible symptom was subtler than that: a write the model
explicitly PERMITS -- your own attribute on anyone's row -- succeeded when
the row was addressed by eid and was refused when the same row was
addressed by lookup ref.
d/entid resolves all three forms, and throws on a malformed one, which is
an ordinary input here rather than a bug.
Does `e` already exist in `db`? False for a tempid -- a negative number, a string, or a tx alias. Handing one to datahike raises `:entity-id/syntax` rather than returning false, so this cannot be written as a bare lookup. It also cannot be written as a bare NUMBER check, which is what it was. A lookup ref (`[:some/unique "x"]`) and a `:db/ident` keyword both name rows that already exist, and both read as "new" under a `number?` test -- so `stamp` claimed ownership of them, the land grab this predicate exists to prevent. The visible symptom was subtler than that: a write the model explicitly PERMITS -- your own attribute on anyone's row -- succeeded when the row was addressed by eid and was refused when the same row was addressed by lookup ref. `d/entid` resolves all three forms, and throws on a malformed one, which is an ordinary input here rather than a bug.
The attribute carrying a row's owner. A ref to a key entity — see the namespace docstring on rotation.
The attribute carrying a row's owner. A ref to a key entity — see the namespace docstring on rotation.
(protocol-attribute? attr)Is attr part of the ledger's own bookkeeping?
By namespace ROOT rather than an enumeration, because a new attribute -- or a
whole new namespace -- beneath any of these is protocol state by
construction and would otherwise be writable the day it is added. That is
exactly what happened once; see protocol-namespace-roots.
urd.stake.intent is the ONE exception and is checked first. It is a REQUEST
namespace: writing it moves nothing, and skuld.staking re-validates every
intent against state the sender does not control before any value moves. See
authz/intent-namespace.
Is `attr` part of the ledger's own bookkeeping? By namespace ROOT rather than an enumeration, because a new attribute -- or a whole new namespace -- beneath any of these is protocol state by construction and would otherwise be writable the day it is added. That is exactly what happened once; see `protocol-namespace-roots`. `urd.stake.intent` is the ONE exception and is checked first. It is a REQUEST namespace: writing it moves nothing, and `skuld.staking` re-validates every intent against state the sender does not control before any value moves. See `authz/intent-namespace`.
Attributes no sender may ever produce a datom for, whatever they own.
Ownership answers "is this row yours". It cannot answer "may you write the
ledger's own bookkeeping", and treating it as sufficient was a minting
vulnerability: :urd.account/balance is an ordinary system attribute, a NEW
row declaring :urd/owner = sender is writable, and stamp supplies that
declaration automatically -- so any funded key could create an account with
an arbitrary balance. Measured: total supply 2,000,000 -> 1,000,001,998,356.
The same reasoning covers :urd/fee (forged fees mint money at
distribution), :urd/sender (forged authorship), :urd/owner written
directly rather than through stamp, :db/* (schema, including in another
key's namespace) and :invariant/* (guards that run on every validator).
The boundary injects its own datoms for these AFTER the check, which is why a blanket refusal here is safe.
:urd/owner is deliberately NOT here. The ownership rule below already
governs it correctly -- assigning yourself as owner of a NEW row is the
stamp, assigning anyone else is refused, and writing it on an existing row
requires already owning that row, which is what makes transfer work. Adding
it here would make the boundary refuse its own stamp.
Attributes no sender may ever produce a datom for, whatever they own. Ownership answers "is this row yours". It cannot answer "may you write the ledger's own bookkeeping", and treating it as sufficient was a minting vulnerability: `:urd.account/balance` is an ordinary system attribute, a NEW row declaring `:urd/owner` = sender is writable, and `stamp` supplies that declaration automatically -- so any funded key could create an account with an arbitrary balance. Measured: total supply 2,000,000 -> 1,000,001,998,356. The same reasoning covers `:urd/fee` (forged fees mint money at distribution), `:urd/sender` (forged authorship), `:urd/owner` written directly rather than through `stamp`, `:db/*` (schema, including in another key's namespace) and `:invariant/*` (guards that run on every validator). The boundary injects its own datoms for these AFTER the check, which is why a blanket refusal here is safe. `:urd/owner` is deliberately NOT here. The ownership rule below already governs it correctly -- assigning yourself as owner of a NEW row is the stamp, assigning anyone else is refused, and writing it on an existing row requires already owning that row, which is what makes transfer work. Adding it here would make the boundary refuse its own stamp.
Namespace ROOTS no sender may write under.
A root protects itself and everything beneath it: db covers db.type and
db.cardinality, and urd.stake covers urd.stake.validator,
urd.stake.delegation and urd.stake.unbonding.
This used to be a set of exact namespace STRINGS, and the difference was a
chain takeover. urd.stake was in the set and the stake projection is stored
under urd.stake.validator / urd.stake.delegation / urd.stake.unbonding
-- none of which equals urd.stake, so none were protected. Any funded
account could transact
{:db/id -1
:urd.stake.validator/id "..." :urd.stake.validator/tokens 999999999
:urd.stake.validator/status :bonded ...}
and be a bonded validator with arbitrary voting power at the next epoch
boundary; or write shares against zero tokens and halt every node on
conservation/assert! permanently; or squat a victim's validator id, since
it is :db.unique/identity.
What made it invisible is worth recording: a comment right here argued that
urd.stake.intent was safe to leave writable BECAUSE the check was on the
exact string. That was true, and it was the same fact that left the
projection open. A rule stated as an exact match has to be re-audited every
time a namespace is added beneath it, and that never happens.
Namespace ROOTS no sender may write under.
A root protects itself and everything beneath it: `db` covers `db.type` and
`db.cardinality`, and `urd.stake` covers `urd.stake.validator`,
`urd.stake.delegation` and `urd.stake.unbonding`.
This used to be a set of exact namespace STRINGS, and the difference was a
chain takeover. `urd.stake` was in the set and the stake projection is stored
under `urd.stake.validator` / `urd.stake.delegation` / `urd.stake.unbonding`
-- none of which equals `urd.stake`, so none were protected. Any funded
account could transact
{:db/id -1
:urd.stake.validator/id "..." :urd.stake.validator/tokens 999999999
:urd.stake.validator/status :bonded ...}
and be a bonded validator with arbitrary voting power at the next epoch
boundary; or write shares against zero tokens and halt every node on
`conservation/assert!` permanently; or squat a victim's validator id, since
it is `:db.unique/identity`.
What made it invisible is worth recording: a comment right here argued that
`urd.stake.intent` was safe to leave writable BECAUSE the check was on the
exact string. That was true, and it was the same fact that left the
projection open. A rule stated as an exact match has to be re-audited every
time a namespace is added beneath it, and that never happens.(stamp db owner tx-data)Add owner to every NEW entity in tx-data.
Deterministic: same db, same tx-data, same result on every validator.
Entities already in the database are left alone — claiming ownership of an existing row is precisely what the check below forbids, and a stamp that did it would hand the sender a way around it.
Add `owner` to every NEW entity in `tx-data`. Deterministic: same db, same tx-data, same result on every validator. Entities already in the database are left alone — claiming ownership of an existing row is precisely what the check below forbids, and a stamp that did it would hand the sender a way around it.
The only attributes permitted on a transaction entity.
The previous rule exempted the transaction entity from ownership entirely,
on the grounds that transaction metadata is not a row anyone owns. That is
true and it was still an unconditional bypass: the sender controls what
lands there, through all four tx aliases and through vector forms stamp
never inspects, so an account could be minted or an invariant registered on
the transaction entity with no check at all.
An allowlist instead of an identity exemption. Anything else on the transaction entity is refused.
The only attributes permitted on a transaction entity. The previous rule exempted the transaction entity from ownership entirely, on the grounds that transaction metadata is not a row anyone owns. That is true and it was still an unconditional bypass: the sender controls what lands there, through all four tx aliases and through vector forms `stamp` never inspects, so an account could be minted or an invariant registered on the transaction entity with no check at all. An allowlist instead of an identity exemption. Anything else on the transaction entity is refused.
Every id datahike reads as "the transaction entity".
All four, not the one you happen to have seen. datahike.db.transaction
accepts :db/current-tx, its string form, and BOTH vendor aliases
(transaction.cljc:65) — "datomic.tx" is a Datomic-compatibility surface
datahike inherited, and kontor's bitemporal helper emits exactly that one.
They matter here because a transaction-metadata map is not a row anyone owns. Stamping it would charge the sender for a datom they did not ask for and assert ownership of the transaction itself.
Every id datahike reads as "the transaction entity". All four, not the one you happen to have seen. `datahike.db.transaction` accepts `:db/current-tx`, its string form, and BOTH vendor aliases (transaction.cljc:65) — `"datomic.tx"` is a Datomic-compatibility surface datahike inherited, and kontor's bitemporal helper emits exactly that one. They matter here because a transaction-metadata map is not a row anyone owns. Stamping it would charge the sender for a datom they did not ask for and assert ownership of the transaction itself.
(violations {:keys [owner sender-ns]} report)Produced datoms owner may not write, under row-level ownership.
owner is the sender's key entity id. Three rules, in order:
own namespace allowed on ANY row. Annotating someone else's entity
with your own attribute is deliberate — see
skuld.ledger.authz on why entity ownership is not a
thing.
another's namespace refused.
system attribute requires owning the row:
owned in db-before -> must be owner. This is also
what makes transfer work and theft fail.
new entity -> the transaction must assign
:urd/owner = owner.
existed, unowned -> refused. A row predating
ownership, or written by genesis, is not up for
grabs.
Produced datoms `owner` may not write, under row-level ownership.
`owner` is the sender's key entity id. Three rules, in order:
own namespace allowed on ANY row. Annotating someone else's entity
with your own attribute is deliberate — see
`skuld.ledger.authz` on why entity ownership is not a
thing.
another's namespace refused.
system attribute requires owning the row:
owned in db-before -> must be `owner`. This is also
what makes transfer work and theft fail.
new entity -> the transaction must assign
`:urd/owner` = `owner`.
existed, unowned -> refused. A row predating
ownership, or written by genesis, is not up for
grabs.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |