Skip to content

Enactment

This section is part of the Ledger.Conway.Enact module of the formal ledger specification

{-# OPTIONS --safe #-}

open import Data.Nat.Properties using (+-0-monoid)
open import Data.Rational using ()

open import Ledger.Prelude
open import Ledger.Conway.Gov.Base

module Ledger.Conway.Enact (gs : _) (open GovStructure gs) where

open import Ledger.Conway.Gov.Actions gs

Figure 'Types-and-function-used-for-the-ENACT-transition-system' contains some definitions required to define the ENACT transition system. EnactEnv is the environment and EnactState the state of ENACT, which enacts a governance action. All governance actions except TreasuryWdrl and Info modify EnactState permanently, which of course can have further consequences. TreasuryWdrl accumulates withdrawal temporarily in the withdrawals field of EnactState, but this information is applied and reset in EPOCH (see Figure 'EPOCH-transition-system'). Also, enacting these governance actions is the only way of modifying EnactState.

Note that all other fields of EnactState also contain a GovActionID since they are HashProtected.

Types and function used for the ENACT transition system

record EnactEnv : Type where
  field
    gid       : GovActionID
    treasury  : Coin
    epoch     : Epoch

record EnactState : Type where
  field
    cc            : HashProtected (Maybe ((Credential  Epoch) × ))
    constitution  : HashProtected (DocHash × Maybe ScriptHash)
    pv            : HashProtected ProtVer
    pparams       : HashProtected PParams
    withdrawals   : RwdAddr  Coin
record HasEnactState {a} (A : Type a) : Type a where
  field EnactStateOf : A  EnactState
open HasEnactState ⦃...⦄ public

instance
  HasPParams-EnactState : HasPParams EnactState
  HasPParams-EnactState .PParamsOf = proj₁  EnactState.pparams

  HasccMaxTermLength-EnactState : HasccMaxTermLength EnactState
  HasccMaxTermLength-EnactState .ccMaxTermLengthOf = PParams.ccMaxTermLength  PParamsOf

  unquoteDecl HasCast-EnactEnv = derive-HasCast
    [ (quote EnactEnv , HasCast-EnactEnv) ]

open EnactState

ccCreds : HashProtected (Maybe ((Credential  Epoch) × ))   Credential
ccCreds (just x   , _)  = dom (x .proj₁)
ccCreds (nothing  , _)  = 

getHash :  {a}  NeedsHash a  Maybe GovActionID
getHash {NoConfidence}     h = just h
getHash {UpdateCommittee}  h = just h
getHash {NewConstitution}  h = just h
getHash {TriggerHF}        h = just h
getHash {ChangePParams}    h = just h
getHash {TreasuryWdrl}     _ = nothing
getHash {Info}             _ = nothing

getHashES : EnactState  GovActionType  Maybe GovActionID
getHashES es NoConfidence       = just (es .cc .proj₂)
getHashES es (UpdateCommittee)  = just (es .cc .proj₂)
getHashES es (NewConstitution)  = just (es .constitution .proj₂)
getHashES es (TriggerHF)        = just (es .pv .proj₂)
getHashES es (ChangePParams)    = just (es .pparams .proj₂)
getHashES es (TreasuryWdrl)     = nothing
getHashES es Info               = nothing

Type of the ENACT transition system

data
  _⊢_⇀⦇_,ENACT⦈_ : EnactEnv  EnactState  GovAction  EnactState  Type
open EnactState

private variable
  s : EnactState
  up : PParamsUpdate
  new : Credential  Epoch
  rem :  Credential
  q : 
  dh : DocHash
  sh : Maybe ScriptHash
  v : ProtVer
  wdrl : RwdAddr  Coin
  t : Coin
  gid : GovActionID
  e : Epoch

instance
  _ = +-0-monoid

Figure 'ENACT-transition-system' and Figure 'ENACT-transition-system-(continued)' define the rules of the ENACT transition system. Usually no preconditions are checked and the state is simply updated (including the GovActionID for the hash protection scheme, if required). The exceptions are UpdateCommittee and TreasuryWdrl:

  • UpdateCommittee requires that maximum terms are respected, and

  • TreasuryWdrl requires that the treasury is able to cover the sum of all withdrawals (old and new).

ENACT transition system

open PParams using (ccMaxTermLength)
open EnactState using (cc)
data _⊢_⇀⦇_,ENACT⦈_ where
  Enact-NoConf :
    ───────────────────────────────────────
    $\begin{pmatrix} \,\href{Ledger.Conway.Enact.html#3996}{\htmlId{5027}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Conway.Enact.html#3985}{\htmlId{5033}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Conway.Enact.html#4016}{\htmlId{5037}{\htmlClass{Generalizable}{\text{e}}}}\, \end{pmatrix}$  s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Conway.Gov.Actions.html#1420}{\htmlId{5050}{\htmlClass{InductiveConstructor}{\text{NoConfidence}}}}\, \\ \,\htmlId{5065}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$ ,ENACT⦈ record s { cc = nothing , gid }

  Enact-UpdComm : let old      = maybe proj₁  (s .cc .proj₁)
                      maxTerm  = ccMaxTermLengthOf s +ᵉ e
                  in
    ∀[ term  range new ] term  maxTerm
    ───────────────────────────────────────
    $\begin{pmatrix} \,\href{Ledger.Conway.Enact.html#3996}{\htmlId{5344}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Conway.Enact.html#3985}{\htmlId{5350}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Conway.Enact.html#4016}{\htmlId{5354}{\htmlClass{Generalizable}{\text{e}}}}\, \end{pmatrix}$  s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Conway.Gov.Actions.html#1455}{\htmlId{5367}{\htmlClass{InductiveConstructor}{\text{UpdateCommittee}}}}\, \\ (\,\href{Ledger.Conway.Enact.html#3852}{\htmlId{5386}{\htmlClass{Generalizable}{\text{new}}}}\, , \,\href{Ledger.Conway.Enact.html#3879}{\htmlId{5392}{\htmlClass{Generalizable}{\text{rem}}}}\, , \,\href{Ledger.Conway.Enact.html#3900}{\htmlId{5398}{\htmlClass{Generalizable}{\text{q}}}}\,) \end{pmatrix}$ ,ENACT⦈
      record s { cc = just ((new ∪ˡ old)  rem  , q) , gid }

  Enact-NewConst :
    ───────────────────────────────────────
    $\begin{pmatrix} \,\href{Ledger.Conway.Enact.html#3996}{\htmlId{5545}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Conway.Enact.html#3985}{\htmlId{5551}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Conway.Enact.html#4016}{\htmlId{5555}{\htmlClass{Generalizable}{\text{e}}}}\, \end{pmatrix}$  s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Conway.Gov.Actions.html#1490}{\htmlId{5568}{\htmlClass{InductiveConstructor}{\text{NewConstitution}}}}\, \\ (\,\href{Ledger.Conway.Enact.html#3908}{\htmlId{5587}{\htmlClass{Generalizable}{\text{dh}}}}\, , \,\href{Ledger.Conway.Enact.html#3923}{\htmlId{5592}{\htmlClass{Generalizable}{\text{sh}}}}\,) \end{pmatrix}$ ,ENACT⦈ record s { constitution = (dh , sh) , gid }

ENACT transition system (continued)

  Enact-HF :
    ───────────────────────────────────────
    $\begin{pmatrix} \,\href{Ledger.Conway.Enact.html#3996}{\htmlId{5774}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Conway.Enact.html#3985}{\htmlId{5780}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Conway.Enact.html#4016}{\htmlId{5784}{\htmlClass{Generalizable}{\text{e}}}}\, \end{pmatrix}$  s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Conway.Gov.Actions.html#1525}{\htmlId{5797}{\htmlClass{InductiveConstructor}{\text{TriggerHF}}}}\, \\ \,\href{Ledger.Conway.Enact.html#3947}{\htmlId{5809}{\htmlClass{Generalizable}{\text{v}}}}\, \end{pmatrix}$ ,ENACT⦈ record s { pv = v , gid }

  Enact-PParams :
    ───────────────────────────────────────
    $\begin{pmatrix} \,\href{Ledger.Conway.Enact.html#3996}{\htmlId{5918}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Conway.Enact.html#3985}{\htmlId{5924}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Conway.Enact.html#4016}{\htmlId{5928}{\htmlClass{Generalizable}{\text{e}}}}\, \end{pmatrix}$  s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Conway.Gov.Actions.html#1560}{\htmlId{5941}{\htmlClass{InductiveConstructor}{\text{ChangePParams}}}}\, \\ \,\href{Ledger.Conway.Enact.html#3831}{\htmlId{5957}{\htmlClass{Generalizable}{\text{up}}}}\, \end{pmatrix}$ ,ENACT⦈
      record s { pparams = applyUpdate (PParamsOf s) up , gid }

  Enact-Wdrl : let newWdrls = s .withdrawals ∪⁺ wdrl in
    ∑[ x  newWdrls ] x  t
    ───────────────────────────────────────
    $\begin{pmatrix} \,\href{Ledger.Conway.Enact.html#3996}{\htmlId{6171}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Conway.Enact.html#3985}{\htmlId{6177}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Conway.Enact.html#4016}{\htmlId{6181}{\htmlClass{Generalizable}{\text{e}}}}\, \end{pmatrix}$  s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Conway.Gov.Actions.html#1595}{\htmlId{6194}{\htmlClass{InductiveConstructor}{\text{TreasuryWdrl}}}}\, \\ \,\href{Ledger.Conway.Enact.html#3961}{\htmlId{6209}{\htmlClass{Generalizable}{\text{wdrl}}}}\, \end{pmatrix}$ ,ENACT⦈ record s { withdrawals = newWdrls }

  Enact-Info :
    ───────────────────────────────────────
    $\begin{pmatrix} \,\href{Ledger.Conway.Enact.html#3996}{\htmlId{6328}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Conway.Enact.html#3985}{\htmlId{6334}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Conway.Enact.html#4016}{\htmlId{6338}{\htmlClass{Generalizable}{\text{e}}}}\, \end{pmatrix}$  s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Conway.Gov.Actions.html#1630}{\htmlId{6351}{\htmlClass{InductiveConstructor}{\text{Info}}}}\, \\ \,\htmlId{6358}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$ ,ENACT⦈ s