{-# OPTIONS --safe #-}
import Data.List as L
open import Ledger.Prelude
open import Ledger.Conway.Specification.Abstract
open import Ledger.Conway.Specification.Transaction using (TransactionStructure)
module Ledger.Conway.Specification.Ledger
(txs : _) (open TransactionStructure txs)
(abs : AbstractFunctions txs) (open AbstractFunctions abs)
where
open import Ledger.Conway.Specification.Enact govStructure
open import Ledger.Conway.Specification.Gov txs
open import Ledger.Conway.Specification.Utxo txs abs
open import Ledger.Conway.Specification.Utxow txs abs
open import Ledger.Conway.Specification.Certs govStructure
open Tx
open GState
open GovActionState
open EnactState using (cc)
record LEnv : Type where
field
slot : Slot
ppolicy : Maybe ScriptHash
pparams : PParams
enactState : EnactState
treasury : Treasury
instance
HasPParams-LEnv : HasPParams LEnv
HasPParams-LEnv .PParamsOf = LEnv.pparams
record LState : Type where
constructor ⟦_,_,_⟧ˡ
field
utxoSt : UTxOState
govSt : GovState
certState : CertState
record HasLState {a} (A : Type a) : Type a where
field LStateOf : A → LState
open HasLState ⦃...⦄ public
instance
HasUTxOState-LState : HasUTxOState LState
HasUTxOState-LState .UTxOStateOf = LState.utxoSt
HasUTxO-LState : HasUTxO LState
HasUTxO-LState .UTxOOf = UTxOOf ∘ UTxOStateOf
HasGovState-LState : HasGovState LState
HasGovState-LState .GovStateOf = LState.govSt
HasCertState-LState : HasCertState LState
HasCertState-LState .CertStateOf = LState.certState
HasDeposits-LState : HasDeposits LState
HasDeposits-LState .DepositsOf = DepositsOf ∘ UTxOStateOf
HasPools-LState : HasPools LState
HasPools-LState .PoolsOf = PoolsOf ∘ CertStateOf
HasGState-LState : HasGState LState
HasGState-LState .GStateOf = GStateOf ∘ CertStateOf
HasDState-LState : HasDState LState
HasDState-LState .DStateOf = DStateOf ∘ CertStateOf
HasPState-LState : HasPState LState
HasPState-LState .PStateOf = PStateOf ∘ CertStateOf
HasVoteDelegs-LState : HasVoteDelegs LState
HasVoteDelegs-LState .VoteDelegsOf = VoteDelegsOf ∘ DStateOf ∘ CertStateOf
HasDonations-LState : HasDonations LState
HasDonations-LState .DonationsOf = DonationsOf ∘ UTxOStateOf
HasFees-LState : HasFees LState
HasFees-LState .FeesOf = FeesOf ∘ UTxOStateOf
HasCCHotKeys-LState : HasCCHotKeys LState
HasCCHotKeys-LState .CCHotKeysOf = CCHotKeysOf ∘ GStateOf
HasDReps-LState : HasDReps LState
HasDReps-LState .DRepsOf = DRepsOf ∘ CertStateOf
open CertState
open DState
open GovVotes
instance
unquoteDecl HasCast-LEnv HasCast-LState = derive-HasCast
((quote LEnv , HasCast-LEnv) ∷ (quote LState , HasCast-LState) ∷ [])
txgov : TxBody → List (GovVote ⊎ GovProposal)
txgov txb = map inj₂ txGovProposals ++ map inj₁ txGovVotes
where open TxBody txb
rmOrphanDRepVotes : CertState → GovState → GovState
rmOrphanDRepVotes cs govSt = L.map (map₂ go) govSt
where
ifDRepRegistered : Credential → Type
ifDRepRegistered c = c ∈ dom (DRepsOf cs)
go : GovActionState → GovActionState
go gas = record gas { votes = record (gas .votes) { gvDRep = filterKeys ifDRepRegistered (gas .votes .gvDRep) } }
allColdCreds : GovState → EnactState → ℙ Credential
allColdCreds govSt es =
ccCreds (es .cc) ∪ concatMapˢ (λ (_ , st) → proposedCC (GovActionOf st)) (fromList govSt)
private variable
Γ : LEnv
s s' s'' : LState
utxoSt utxoSt' : UTxOState
govSt govSt' : GovState
certState certState' : CertState
tx : Tx
slot : Slot
ppolicy : Maybe ScriptHash
pp : PParams
enactState : EnactState
treasury : Treasury
data _⊢_⇀⦇_,LEDGER⦈_ : LEnv → LState → Tx → LState → Type where
LEDGER-V :
let txb = tx .body
open TxBody txb
in
∙ isValid tx ≡ true
∙ $\begin{pmatrix} \,\href{Ledger.Conway.Specification.Ledger.html#3639}{\htmlId{3992}{\htmlClass{Generalizable}{\text{slot}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3713}{\htmlId{3999}{\htmlClass{Generalizable}{\text{pp}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3784}{\htmlId{4004}{\htmlClass{Generalizable}{\text{treasury}}}}\, \end{pmatrix}$ ⊢ utxoSt ⇀⦇ tx ,UTXOW⦈ utxoSt'
∙ $\begin{pmatrix} \,\href{Ledger.Core.Specification.Epoch.html#858}{\htmlId{4057}{\htmlClass{Function}{\text{epoch}}}}\, \,\href{Ledger.Conway.Specification.Ledger.html#3639}{\htmlId{4063}{\htmlClass{Generalizable}{\text{slot}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3713}{\htmlId{4070}{\htmlClass{Generalizable}{\text{pp}}}}\, \\ \,\href{Ledger.Conway.Specification.Transaction.html#3463}{\htmlId{4075}{\htmlClass{Function}{\text{txGovVotes}}}}\, \\ \,\href{Ledger.Conway.Specification.Transaction.html#3288}{\htmlId{4088}{\htmlClass{Function}{\text{txWithdrawals}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3250}{\htmlId{4104}{\htmlClass{Function}{\text{allColdCreds}}}}\, \,\href{Ledger.Conway.Specification.Ledger.html#3539}{\htmlId{4117}{\htmlClass{Generalizable}{\text{govSt}}}}\, \,\href{Ledger.Conway.Specification.Ledger.html#3747}{\htmlId{4123}{\htmlClass{Generalizable}{\text{enactState}}}}\, \end{pmatrix}$ ⊢ certState ⇀⦇ txCerts ,CERTS⦈ certState'
∙ $\begin{pmatrix} \,\href{Ledger.Conway.Specification.Transaction.html#3180}{\htmlId{4188}{\htmlClass{Function}{\text{txId}}}}\, \\ \,\href{Ledger.Core.Specification.Epoch.html#858}{\htmlId{4195}{\htmlClass{Function}{\text{epoch}}}}\, \,\href{Ledger.Conway.Specification.Ledger.html#3639}{\htmlId{4201}{\htmlClass{Generalizable}{\text{slot}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3713}{\htmlId{4208}{\htmlClass{Generalizable}{\text{pp}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3670}{\htmlId{4213}{\htmlClass{Generalizable}{\text{ppolicy}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3747}{\htmlId{4223}{\htmlClass{Generalizable}{\text{enactState}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3584}{\htmlId{4236}{\htmlClass{Generalizable}{\text{certState'}}}}\, \\ \,\href{Class.IsSet.html#916}{\htmlId{4249}{\htmlClass{Function}{\text{dom}}}}\, \,\htmlId{4253}{\htmlClass{Symbol}{\text{(}}}\,\,\href{Ledger.Conway.Specification.Certs.html#1727}{\htmlId{4254}{\htmlClass{Field}{\text{RewardsOf}}}}\, \,\href{Ledger.Conway.Specification.Ledger.html#3574}{\htmlId{4264}{\htmlClass{Generalizable}{\text{certState}}}}\,\,\htmlId{4273}{\htmlClass{Symbol}{\text{)}}}\, \end{pmatrix}$ ⊢ rmOrphanDRepVotes certState' govSt ⇀⦇ txgov txb ,GOVS⦈ govSt'
────────────────────────────────
$\begin{pmatrix} \,\href{Ledger.Conway.Specification.Ledger.html#3639}{\htmlId{4388}{\htmlClass{Generalizable}{\text{slot}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3670}{\htmlId{4395}{\htmlClass{Generalizable}{\text{ppolicy}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3713}{\htmlId{4405}{\htmlClass{Generalizable}{\text{pp}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3747}{\htmlId{4410}{\htmlClass{Generalizable}{\text{enactState}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3784}{\htmlId{4423}{\htmlClass{Generalizable}{\text{treasury}}}}\, \end{pmatrix}$ ⊢ $\begin{pmatrix} \,\href{Ledger.Conway.Specification.Ledger.html#3503}{\htmlId{4438}{\htmlClass{Generalizable}{\text{utxoSt}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3539}{\htmlId{4447}{\htmlClass{Generalizable}{\text{govSt}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3574}{\htmlId{4455}{\htmlClass{Generalizable}{\text{certState}}}}\, \end{pmatrix}$ ⇀⦇ tx ,LEDGER⦈ $\begin{pmatrix} \,\href{Ledger.Conway.Specification.Ledger.html#3510}{\htmlId{4484}{\htmlClass{Generalizable}{\text{utxoSt'}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3545}{\htmlId{4494}{\htmlClass{Generalizable}{\text{govSt'}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3584}{\htmlId{4503}{\htmlClass{Generalizable}{\text{certState'}}}}\, \end{pmatrix}$
LEDGER-I :
∙ isValid tx ≡ false
∙ $\begin{pmatrix} \,\href{Ledger.Conway.Specification.Ledger.html#3639}{\htmlId{4567}{\htmlClass{Generalizable}{\text{slot}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3713}{\htmlId{4574}{\htmlClass{Generalizable}{\text{pp}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3784}{\htmlId{4579}{\htmlClass{Generalizable}{\text{treasury}}}}\, \end{pmatrix}$ ⊢ utxoSt ⇀⦇ tx ,UTXOW⦈ utxoSt'
────────────────────────────────
$\begin{pmatrix} \,\href{Ledger.Conway.Specification.Ledger.html#3639}{\htmlId{4668}{\htmlClass{Generalizable}{\text{slot}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3670}{\htmlId{4675}{\htmlClass{Generalizable}{\text{ppolicy}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3713}{\htmlId{4685}{\htmlClass{Generalizable}{\text{pp}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3747}{\htmlId{4690}{\htmlClass{Generalizable}{\text{enactState}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3784}{\htmlId{4703}{\htmlClass{Generalizable}{\text{treasury}}}}\, \end{pmatrix}$ ⊢ $\begin{pmatrix} \,\href{Ledger.Conway.Specification.Ledger.html#3503}{\htmlId{4718}{\htmlClass{Generalizable}{\text{utxoSt}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3539}{\htmlId{4727}{\htmlClass{Generalizable}{\text{govSt}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3574}{\htmlId{4735}{\htmlClass{Generalizable}{\text{certState}}}}\, \end{pmatrix}$ ⇀⦇ tx ,LEDGER⦈ $\begin{pmatrix} \,\href{Ledger.Conway.Specification.Ledger.html#3510}{\htmlId{4764}{\htmlClass{Generalizable}{\text{utxoSt'}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3539}{\htmlId{4774}{\htmlClass{Generalizable}{\text{govSt}}}}\, \\ \,\href{Ledger.Conway.Specification.Ledger.html#3574}{\htmlId{4782}{\htmlClass{Generalizable}{\text{certState}}}}\, \end{pmatrix}$
pattern LEDGER-V⋯ w x y z = LEDGER-V (w , x , y , z)
pattern LEDGER-I⋯ y z = LEDGER-I (y , z)
_⊢_⇀⦇_,LEDGERS⦈_ : LEnv → LState → List Tx → LState → Type
_⊢_⇀⦇_,LEDGERS⦈_ = ReflexiveTransitiveClosure {sts = _⊢_⇀⦇_,LEDGER⦈_}