Liking cljdoc? Tell your friends :D

Ownership

Two rules decide whether you may write a datom, and the second exists because the first could not express a shared schema.

Rule one — your namespace is yours. A key owns :<its-hex-namespace>/*, anywhere, on any row. Self-evident from the attribute name, no registry.

Rule two — a system attribute follows its row's owner. Everything whose namespace is not a 64-character hex string is a system attribute: :db/ident, :kontor.account/path, an application's own schema. Those are readable by everyone and writable by the row's owner.

Rule one alone was not enough. Measured: an unmodified kontor.book/entry-tx-data posting had all 20 of its datoms refused, because a shared accounting schema names its attributes after the schema, not after whoever is writing.

The owner is a ref

:urd/owner points at the key's entity — the same entity that holds the balance, so a balance and an ownership record cannot disagree about who a key is. See identity for the measured cost of the alternatives.

The boundary stamps; you do not

New entities get :urd/owner added automatically during admission. The client does not supply it, because the client is often a library that knows nothing about this ledger — kontor's builder emits four entities per posting and has never heard of :urd/owner.

One thing you do have to supply: a :db/id. Stamping only sees entities that have one. A map without a :db/id is invisible to it, arrives unowned, and is refused :new-row-must-declare-owner.

Auto-assigning one was considered and rejected: a map with no :db/id may still upsert onto an existing entity through a :db/unique attribute, and stamping that would claim ownership of a row the sender does not own.

The rules, as a matrix

refusalwhen
:not-transaction-metadataa datom on the transaction entity outside the allowlist
:protocol-attributeledger bookkeeping — checked before ownership
(allowed)the attribute's namespace is yours, on any row
:other-users-namespaceanother key's hex namespace
:not-row-ownera system attribute on a row owned by somebody else
:unowned-rowa system attribute on an existing row with no owner
:new-row-must-declare-ownera system attribute on a new row that assigns no owner

Transfer falls out of this for free: rewriting :urd/owner on a row you own is an ordinary write. Theft does not, because rewriting it on a row you do not own trips :not-row-owner.

A cardinality-one change produces a retraction and an addition, and both are checked. Checking only additions would let you delete anything.

Protocol state is nobody's

Owning a row is not authority to write the ledger's own bookkeeping. Two mechanisms:

Specific attributes — :urd/fee and :urd/sender. Not :urd/owner, deliberately: adding it would make the boundary refuse its own stamp.

Namespace roots — db, invariant, urd.account, urd.stake, rules. A root protects itself and everything beneath it, matched segment-wise, so urd.stakeholder is not under urd.stake.

That was once a set of exact namespace strings, and the difference was a chain takeover. urd.stake was in the set; the stake projection is stored under urd.stake.validator, urd.stake.delegation and urd.stake.unbonding, none of which equals urd.stake. Any funded account could write itself a bonded validator with arbitrary voting power, or write shares against zero tokens and halt every node permanently, or squat a victim's validator id.

What made it invisible: a comment on that very line argued urd.stake.intent was safe to leave writable because the match was exact. That was true, and it was the same fact that left the projection open.

The transaction entity

Only :db/txInstant, :urd/sender and :urd/fee may appear there — an allowlist replacing an identity exemption that was an unconditional bypass. All four tempid aliases (:db/current-tx, ":db/current-tx", "datomic.tx", "datahike.tx") are recognised; datahike accepts all four, and kontor's bitemporal helper emits datomic.tx, which is how the gap was found.

Relatedly, fees are counted by walking datoms and requiring that the fee sits on its own transaction entity. The naive query credited a planted fee of 999,999,999 against a real fee of 1,375.

Asking the protocol for something

Ownership divides the world in two — your namespace, or protocol state — and that left no way to ask the protocol for anything. Staking made it concrete: a delegation is not a row in your namespace, and urd.stake is refused.

So a third class: urd.stake.intent, a request namespace any authenticated sender may write.

[{:db/id "intent"
  :urd.stake.intent/op :delegate
  :urd.stake.intent/validator "<validator namespace>"
  :urd.stake.intent/amount 3000000}]

An intent is inert, and that is the entire security argument. Writing one moves nothing and proves nothing; it records that a sender asked, and they pay for the bytes like any other write. The protocol reads those datoms at the end of the block, re-validates every one against state the sender does not control — balances, share counts, whether the validator exists — and only then moves value.

The moment an attribute in that namespace means something to anything other than the end-of-block interpreter, that stops being true.

What ownership is not

Scope is per attribute, never per entity. "Who owns entity 42" has no answer, and does not need one: several keys may write their own attributes on one row.

See also

Transactions · Staking for what intents do · Invariants for guards on attributes you own

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close