Enactment
{-# OPTIONS --safe #-}
open import Data.Nat.Properties using (+-0-monoid)
open import Data.Rational using (ℚ)
open import Ledger.Prelude
open import Ledger.Dijkstra.Specification.Gov.Base
module Ledger.Dijkstra.Specification.Enact (gs : _) (open GovStructure gs) where
open import Ledger.Dijkstra.Specification.Gov.Actions gs
Auxiliary Types and Functions
record EnactEnv : Type where
field
gid : GovActionID
treasury : Treasury
epoch : Epoch
record EnactState : Type where
field
cc : HashProtected (Maybe ((Credential ⇀ Epoch) × ℚ))
constitution : HashProtected (DocHash × Maybe ScriptHash)
pv : HashProtected ProtVer
pparams : HashProtected PParams
withdrawals : Withdrawals
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
HasWithdrawals-EnactState : HasWithdrawals EnactState
HasWithdrawals-EnactState .WithdrawalsOf = EnactState.withdrawals
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 {TriggerHardFork} h = just h
getHash {ChangePParams} h = just h
getHash {TreasuryWithdrawal} _ = 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 (TriggerHardFork) = just (es .pv .proj₂)
getHashES es (ChangePParams) = just (es .pparams .proj₂)
getHashES es (TreasuryWithdrawal) = nothing
getHashES es Info = nothing
private variable
s : EnactState
up : PParamsUpdate
new : Credential ⇀ Epoch
removed : ℙ Credential
q : ℚ
dHash : DocHash
sHash : Maybe ScriptHash
protVer : ProtVer
wdrls : Withdrawals
t : Treasury
gid : GovActionID
ep : Epoch
instance
_ = +-0-monoid
The ENACT Transition System
data _⊢_⇀⦇_,ENACT⦈_ : EnactEnv → EnactState → GovAction → EnactState → Type where
Enact-NoConf :
───────────────────────────────────────
$\begin{pmatrix} \,\href{Ledger.Dijkstra.Specification.Enact.html#2934}{\htmlId{3237}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Dijkstra.Specification.Enact.html#2912}{\htmlId{3243}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Dijkstra.Specification.Enact.html#2959}{\htmlId{3247}{\htmlClass{Generalizable}{\text{ep}}}}\, \end{pmatrix}$ ⊢ s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Dijkstra.Specification.Gov.Actions.html#995}{\htmlId{3261}{\htmlClass{InductiveConstructor}{\text{NoConfidence}}}}\, \\ \,\htmlId{3276}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$ ,ENACT⦈ record s { cc = nothing , gid }
Enact-UpdComm : let old = maybe proj₁ ∅ (s .cc .proj₁)
maxTerm = CCMaxTermLengthOf s +ᵉ ep
in
∀[ term ∈ range new ] term ≤ maxTerm
───────────────────────────────────────
$\begin{pmatrix} \,\href{Ledger.Dijkstra.Specification.Enact.html#2934}{\htmlId{3556}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Dijkstra.Specification.Enact.html#2912}{\htmlId{3562}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Dijkstra.Specification.Enact.html#2959}{\htmlId{3566}{\htmlClass{Generalizable}{\text{ep}}}}\, \end{pmatrix}$ ⊢ s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Dijkstra.Specification.Gov.Actions.html#1033}{\htmlId{3580}{\htmlClass{InductiveConstructor}{\text{UpdateCommittee}}}}\, \\ \,\htmlId{3598}{\htmlClass{Symbol}{\text{(}}}\,\,\href{Ledger.Dijkstra.Specification.Enact.html#2742}{\htmlId{3599}{\htmlClass{Generalizable}{\text{new}}}}\, , \,\href{Ledger.Dijkstra.Specification.Enact.html#2774}{\htmlId{3605}{\htmlClass{Generalizable}{\text{removed}}}}\, , \,\href{Ledger.Dijkstra.Specification.Enact.html#2800}{\htmlId{3615}{\htmlClass{Generalizable}{\text{q}}}}\,\,\htmlId{3616}{\htmlClass{Symbol}{\text{)}}}\, \end{pmatrix}$ ,ENACT⦈
record s { cc = just ((new ∪ˡ old) ∣ removed ᶜ , q) , gid }
Enact-NewConst :
───────────────────────────────────────
$\begin{pmatrix} \,\href{Ledger.Dijkstra.Specification.Enact.html#2934}{\htmlId{3766}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Dijkstra.Specification.Enact.html#2912}{\htmlId{3772}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Dijkstra.Specification.Enact.html#2959}{\htmlId{3776}{\htmlClass{Generalizable}{\text{ep}}}}\, \end{pmatrix}$ ⊢ s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Dijkstra.Specification.Gov.Actions.html#1071}{\htmlId{3790}{\htmlClass{InductiveConstructor}{\text{NewConstitution}}}}\, \\ \,\htmlId{3808}{\htmlClass{Symbol}{\text{(}}}\,\,\href{Ledger.Dijkstra.Specification.Enact.html#2815}{\htmlId{3809}{\htmlClass{Generalizable}{\text{dHash}}}}\, , \,\href{Ledger.Dijkstra.Specification.Enact.html#2836}{\htmlId{3817}{\htmlClass{Generalizable}{\text{sHash}}}}\,\,\htmlId{3822}{\htmlClass{Symbol}{\text{)}}}\, \end{pmatrix}$ ,ENACT⦈ record s { constitution = (dHash , sHash) , gid }
Enact-HF :
───────────────────────────────────────
$\begin{pmatrix} \,\href{Ledger.Dijkstra.Specification.Enact.html#2934}{\htmlId{3950}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Dijkstra.Specification.Enact.html#2912}{\htmlId{3956}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Dijkstra.Specification.Enact.html#2959}{\htmlId{3960}{\htmlClass{Generalizable}{\text{ep}}}}\, \end{pmatrix}$ ⊢ s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Dijkstra.Specification.Gov.Actions.html#1109}{\htmlId{3974}{\htmlClass{InductiveConstructor}{\text{TriggerHardFork}}}}\, \\ \,\href{Ledger.Dijkstra.Specification.Enact.html#2866}{\htmlId{3992}{\htmlClass{Generalizable}{\text{protVer}}}}\, \end{pmatrix}$ ,ENACT⦈ record s { pv = protVer , gid }
Enact-PParams :
───────────────────────────────────────
$\begin{pmatrix} \,\href{Ledger.Dijkstra.Specification.Enact.html#2934}{\htmlId{4113}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Dijkstra.Specification.Enact.html#2912}{\htmlId{4119}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Dijkstra.Specification.Enact.html#2959}{\htmlId{4123}{\htmlClass{Generalizable}{\text{ep}}}}\, \end{pmatrix}$ ⊢ s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Dijkstra.Specification.Gov.Actions.html#1147}{\htmlId{4137}{\htmlClass{InductiveConstructor}{\text{ChangePParams}}}}\, \\ \,\href{Ledger.Dijkstra.Specification.Enact.html#2715}{\htmlId{4153}{\htmlClass{Generalizable}{\text{up}}}}\, \end{pmatrix}$ ,ENACT⦈
record s { pparams = applyUpdate (PParamsOf s) up , gid }
Enact-Wdrl : let newWdrls = s .withdrawals ∪⁺ wdrls in
∑[ x ← newWdrls ] x ≤ t
───────────────────────────────────────
$\begin{pmatrix} \,\href{Ledger.Dijkstra.Specification.Enact.html#2934}{\htmlId{4368}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Dijkstra.Specification.Enact.html#2912}{\htmlId{4374}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Dijkstra.Specification.Enact.html#2959}{\htmlId{4378}{\htmlClass{Generalizable}{\text{ep}}}}\, \end{pmatrix}$ ⊢ s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Dijkstra.Specification.Gov.Actions.html#1185}{\htmlId{4392}{\htmlClass{InductiveConstructor}{\text{TreasuryWithdrawal}}}}\, \\ \,\href{Ledger.Dijkstra.Specification.Enact.html#2887}{\htmlId{4413}{\htmlClass{Generalizable}{\text{wdrls}}}}\, \end{pmatrix}$ ,ENACT⦈ record s { withdrawals = newWdrls }
Enact-Info :
───────────────────────────────────────
$\begin{pmatrix} \,\href{Ledger.Dijkstra.Specification.Enact.html#2934}{\htmlId{4533}{\htmlClass{Generalizable}{\text{gid}}}}\, \\ \,\href{Ledger.Dijkstra.Specification.Enact.html#2912}{\htmlId{4539}{\htmlClass{Generalizable}{\text{t}}}}\, \\ \,\href{Ledger.Dijkstra.Specification.Enact.html#2959}{\htmlId{4543}{\htmlClass{Generalizable}{\text{ep}}}}\, \end{pmatrix}$ ⊢ s ⇀⦇ $\begin{pmatrix} \,\href{Ledger.Dijkstra.Specification.Gov.Actions.html#1223}{\htmlId{4557}{\htmlClass{InductiveConstructor}{\text{Info}}}}\, \\ \,\htmlId{4564}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$ ,ENACT⦈ s