The whole transaction boundary, in one place.
signature -> nonce -> funds -> ONE d/with -> scope -> invariants -> charge
policy is node configuration. envelope is whatever arrived on the wire.
They are separate parameters because merging them was a vulnerability: an
earlier version destructured :system-writers and :schedule from the same
map that carried the signature, and the signature covers only
{:chain :sender :nonce :tx-data}. A sender could therefore declare
themselves a system writer, and supply a fee schedule that priced their own
transaction at zero. Both were demonstrated.
:chain is signed AND compared against the node's own configured chain
here. Signing it is not enough on its own -- if the verifier takes the chain
from the same envelope, an attacker simply signs for whatever chain they
declare, and the domain separation urd.consensus.auth exists to provide
evaporates.
Each step is cheaper than the one after it, and each can refuse alone. A
signature check is one Ed25519 operation against a key we hold; a nonce and
a balance are lookups; d/with walks the database and allocates; invariants
run Datalog someone else wrote. Doing the expensive half first is how a node
is made to work hard for a message anyone can send.
The speculative transaction is run ONCE and gives us the price, the scope check, the invariant dispatch, and the effects to apply.
Computing any of these from the SUBMITTED tx-data instead is the single
mistake this codebase has made three times -- in attribute scoping, in row
ownership through the :db/isComponent cascade, and in invariant dispatch.
Submitted forms do not name what a transaction touches.
It applies the fee and the nonce bump without the sender's effects. A refusal that wrote nothing would leave the nonce unspent, and a transaction that can be retried for free after being refused is a free retry loop.
The whole transaction boundary, in one place.
signature -> nonce -> funds -> ONE d/with -> scope -> invariants -> charge
## Policy and envelope are separate arguments, deliberately
`policy` is node configuration. `envelope` is whatever arrived on the wire.
They are separate parameters because merging them was a vulnerability: an
earlier version destructured `:system-writers` and `:schedule` from the same
map that carried the signature, and the signature covers only
`{:chain :sender :nonce :tx-data}`. A sender could therefore declare
themselves a system writer, and supply a fee schedule that priced their own
transaction at zero. Both were demonstrated.
`:chain` is signed AND compared against the node's own configured chain
here. Signing it is not enough on its own -- if the verifier takes the chain
from the same envelope, an attacker simply signs for whatever chain they
declare, and the domain separation `urd.consensus.auth` exists to provide
evaporates.
## Why the order is what it is
Each step is cheaper than the one after it, and each can refuse alone. A
signature check is one Ed25519 operation against a key we hold; a nonce and
a balance are lookups; `d/with` walks the database and allocates; invariants
run Datalog someone else wrote. Doing the expensive half first is how a node
is made to work hard for a message anyone can send.
## One d/with, four answers
The speculative transaction is run ONCE and gives us the price, the scope
check, the invariant dispatch, and the effects to apply.
Computing any of these from the SUBMITTED tx-data instead is the single
mistake this codebase has made three times -- in attribute scoping, in row
ownership through the `:db/isComponent` cascade, and in invariant dispatch.
Submitted forms do not name what a transaction touches.
## A refused transaction still transacts
It applies the fee and the nonce bump without the sender's effects. A
refusal that wrote nothing would leave the nonce unspent, and a transaction
that can be retried for free after being refused is a free retry loop.(admit conn
{:keys [chain schedule] :or {schedule cost/default-schedule} :as _policy}
{:keys [sender public-key signature nonce tx-data] :as envelope})Decide, price, and produce the transaction to apply.
policy is node configuration: {:chain c :schedule s}.
envelope is wire data: {:sender hex :public-key bytes :signature s :nonce n :tx-data [...]}.
Returns {:ok? bool :reason kw :fee n :apply [...] :violations [...]}.
Decide, price, and produce the transaction to apply.
`policy` is node configuration: `{:chain c :schedule s}`.
`envelope` is wire data: `{:sender hex :public-key bytes :signature s
:nonce n :tx-data [...]}`.
Returns `{:ok? bool :reason kw :fee n :apply [...] :violations [...]}`.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 |