singular_state/fold
Fold of a registry state: registrations and terminations.
Responsibility
The decision sites of the model’s fold for registration and termination
changes: one function per guard, and fold, which conjoins them for the
spend handler of the state script.
Dependencies
singular_state/state for recognition and the mint comparison;
singular_state/genesis for the outputs that carry the state token;
singular_state/preimage for the role names; the Merkle Patricia
Forestry library for the proofs of absence and of presence and the new
root.
Assumptions
The ledger runs the spend handler once for each input at the state script, and the mint handler once when the state policy is minted. The state policy is the hash of the state script, which is also the credential of the state address. The trie library’s proofs are assumed sound.
Invariants
A fold spends the state of a registry once and writes the computed root into the one bare output that continues it, at the same script. Each registration consumes the one approval of exactly that change, proves its key absent, and mints one token for the key into the holding the approval commits to, with at least the deposit it commits to. Each termination consumes the one approval of exactly that change, proves its key active, finds the key’s one active token on the request that carries the approval, and burns both; the leaf of the key becomes terminal. Nothing else is minted or burned under the state policy.
Types
One change of a fold, in the order of the model’s Change. A termination
names the request that carries its approval and the active token, the key,
and the proof that shows the key active.
Constructors
-
Register { request: OutputReference, key: ByteArray, holding: Int, deposit: Int, proof: Proof, } -
Terminate { request: OutputReference, key: ByteArray, proof: Proof }
The redeemer of a state output: the seed that names the registry, and the changes folded into it.
Constructors
-
Fold { seed: OutputReference, changes: List<Change> }
Constants
The leaf the trie binds to a registered key: the model’s known active.
Functions
The registry created by spending seed under state_policy.
The datum an application output carries, when it carries one: the data of an inline datum, whatever its shape. The category of an output is its role in the fold, not the shape of its datum.
fold_before(
state_policy: PolicyId,
seed: OutputReference,
own_reference: OutputReference,
inputs: List<Input>,
) -> Bool
Model guard foldBefore: the spent state is recognised from the supplied
seed, its datum is the root of the trie before, and it is spent once.
Model guard foldNonempty: the fold carries at least one change.
Model guard foldDistinct: no two changes consume the same request.
Model guard foldPairing: an input carries an application asset exactly
when a change consumes it.
Model guard changeReference: exactly one input spends the request.
Model guard changeApprovalShape: the request input carries one token of
the application policy, at quantity one.
approval_for(
registry: RegistryIdentity,
outputs: List<Output>,
change: Change,
) -> Option<AssetName>
The approval a change commits to, recomputed from the change. A registration
commits to the holding output it names; the output that carries the state
token is the model’s root category and has none, and any other output is
an application output. A termination commits to the key and the registry
alone.
Model guard changeApproval: the application token the request carries is
the approval recomputed from the change.
Model guard changeApprovalBurn: the approval is burned.
Model guard changeLeaf, for a registration: the trie proof shows the key
absent.
Model separateHolding: no other registration names the same holding.
Model oneNewToken: the holding holds one new token in total.
registration_placement(
registry: RegistryIdentity,
outputs: List<Output>,
changes: List<Change>,
request: OutputReference,
key: ByteArray,
holding: Int,
) -> Bool
Model guard registrationPlacement: the token of the key is in the holding
once, and in no other output.
Model guard registrationMint: one token of the key is minted.
Model guard registrationDeposit: the holding holds at least the deposit.
Model guard changeLeaf, for a termination: the trie proof shows the key
active.
Model guard terminationHeld: the request input holds the active token of
the key once.
Model guard terminationBurn: the active token of the key is burned once.
apply_change(
application_policy: PolicyId,
registry: RegistryIdentity,
tx: Transaction,
changes: List<Change>,
trie: MerklePatriciaForestry,
change: Change,
) -> Option<MerklePatriciaForestry>
One change applied to the trie: every guard of the change holds. The trie
after it is None when one does not.
change_batch(
application_policy: PolicyId,
registry: RegistryIdentity,
tx: Transaction,
trie: MerklePatriciaForestry,
changes: List<Change>,
) -> Option<MerklePatriciaForestry>
Model changeBatch: the changes applied in order to the trie before.
Model guard foldTrie: the batch was applied, and the continuing state
carries the root of the trie it produced.
Model guard foldContinuation: exactly one output carries the state
token, and it carries nothing but ADA besides.
Model guard foldAddress: the continuing state is at the same payment
credential.
Model guard foldValue: the continuing state holds at least the ADA the
spent one held.
Model guard foldWholePolicy: the whole state-policy mint is exactly one
token for each registered key and the burn of one for each terminated key.
fold_no_new_consumed(
transaction_id: TransactionId,
changes: List<Change>,
inputs: List<Input>,
) -> Bool
Model guard foldNoNewConsumed: no new holding is also an input.
The mint handler of a fold: a state input is spent, and its spend handler decides the fold.