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

leaf_active: ByteArray = #"01"

The leaf the trie binds to a registered key: the model’s known active.

leaf_terminal: ByteArray = #"02"

The leaf the trie binds to a terminated key: the model’s known terminal.

Functions

request_of(change: Change) -> OutputReference

The request input a change consumes.

key_of(change: Change) -> ByteArray

The key a change is about.

registry_identity(
  state_policy: PolicyId,
  seed: OutputReference,
) -> RegistryIdentity

The registry created by spending seed under state_policy.

application_datum(datum: Datum) -> Option<Data>

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.

fold_nonempty(changes: List<Change>) -> Bool

Model guard foldNonempty: the fold carries at least one change.

fold_distinct(changes: List<Change>) -> Bool

Model guard foldDistinct: no two changes consume the same request.

fold_pairing(
  application_policy: PolicyId,
  changes: List<Change>,
  inputs: List<Input>,
) -> Bool

Model guard foldPairing: an input carries an application asset exactly when a change consumes it.

change_reference(inputs: List<Input>, request: OutputReference) -> Bool

Model guard changeReference: exactly one input spends the request.

change_approval_shape(application_policy: PolicyId, request: Output) -> Bool

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.

change_approval(
  application_policy: PolicyId,
  request: Output,
  approval: AssetName,
) -> Bool

Model guard changeApproval: the application token the request carries is the approval recomputed from the change.

change_approval_burn(
  application_policy: PolicyId,
  approval: AssetName,
  mint: Value,
) -> Bool

Model guard changeApprovalBurn: the approval is burned.

change_leaf(trie: MerklePatriciaForestry, key: ByteArray, proof: Proof) -> Bool

Model guard changeLeaf, for a registration: the trie proof shows the key absent.

separate_holding(
  changes: List<Change>,
  request: OutputReference,
  holding: Int,
) -> Bool

Model separateHolding: no other registration names the same holding.

one_new_token(
  registry: RegistryIdentity,
  changes: List<Change>,
  holding: Output,
) -> Bool

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.

registration_mint(
  registry: RegistryIdentity,
  key: ByteArray,
  mint: Value,
) -> Bool

Model guard registrationMint: one token of the key is minted.

registration_deposit(deposit: Int, holding: Output) -> Bool

Model guard registrationDeposit: the holding holds at least the deposit.

change_leaf_active(
  trie: MerklePatriciaForestry,
  key: ByteArray,
  proof: Proof,
) -> Bool

Model guard changeLeaf, for a termination: the trie proof shows the key active.

termination_held(
  registry: RegistryIdentity,
  key: ByteArray,
  request: Output,
) -> Bool

Model guard terminationHeld: the request input holds the active token of the key once.

termination_burn(
  registry: RegistryIdentity,
  key: ByteArray,
  mint: Value,
) -> Bool

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.

fold_trie(result: Option<MerklePatriciaForestry>, after: Output) -> Bool

Model guard foldTrie: the batch was applied, and the continuing state carries the root of the trie it produced.

fold_continuation(
  state_policy: PolicyId,
  seed: OutputReference,
  outputs: List<Output>,
) -> Bool

Model guard foldContinuation: exactly one output carries the state token, and it carries nothing but ADA besides.

fold_address(before: Output, after: Output) -> Bool

Model guard foldAddress: the continuing state is at the same payment credential.

fold_value(before: Output, after: Output) -> Bool

Model guard foldValue: the continuing state holds at least the ADA the spent one held.

fold_whole_policy(
  registry: RegistryIdentity,
  changes: List<Change>,
  mint: Value,
) -> Bool

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.

fold_spends_state_script(state_policy: PolicyId, inputs: List<Input>) -> Bool

The mint handler of a fold: a state input is spent, and its spend handler decides the fold.

fold(
  application_policy: PolicyId,
  seed: OutputReference,
  changes: List<Change>,
  own_reference: OutputReference,
  tx: Transaction,
) -> Bool

The model’s fold for the state script of application_policy, spending the state output own_reference of the registry created from seed.

Search Document