GenMinspend
General Minimum Spending Condition
isRefundCert : DCert → Bool
isRefundCert (dereg c _) = true
isRefundCert (deregdrep c _) = true
isRefundCert _ = false
noRefundCert : List DCert → Type _
noRefundCert l = All (λ cert → isRefundCert cert ≡ false) l
opaque
unfolding List-Model
unfolding finiteness
fin∘list[] : {A : Type} → proj₁ (finiteness{A = A} ∅) ≡ []
fin∘list[] = refl
fin∘list∷[] : {A : Type} {a : A} → proj₁ (finiteness ❴ a ❵) ≡ [ a ]
fin∘list∷[] = refl
coin∅ : getCoin{A = Deposits} ∅ ≡ 0
coin∅ = begin
foldr (λ x → (proj₂ x) +_) 0 (deduplicate _≟_ (proj₁ (finiteness ∅)))
≡⟨ cong (λ u → (foldr (λ x → (proj₂ x) +_) 0 (deduplicate _≟_ u))) fin∘list[] ⟩
foldr (λ (x : DepositPurpose × Coin) → (proj₂ x) +_) 0 (deduplicate _≟_ [])
≡⟨ cong (λ u → (foldr (λ (x : DepositPurpose × Coin) → (proj₂ x) +_) 0 u))
{x = deduplicate _≟_ []} {y = []} refl ⟩
foldr (λ (x : DepositPurpose × Coin) → (proj₂ x) +_) 0 []
≡⟨ refl ⟩
0 ∎
where open Prelude.≡-Reasoning
getCoin-singleton : ((dp , c) : DepositPurpose × Coin) → indexedSumᵛ' id ❴ (dp , c) ❵ ≡ c
getCoin-singleton _ = indexedSum-singleton' {A = DepositPurpose × Coin} {f = proj₂} (finiteness _)
module _ -- ASSUMPTION --
(gc-hom : (d₁ d₂ : Deposits) → getCoin (d₁ ∪⁺ d₂) ≡ getCoin d₁ + getCoin d₂)
where
∪⁺singleton≡ : {deps : Deposits} {(dp , c) : DepositPurpose × Coin}
→ getCoin (deps ∪⁺ ❴ (dp , c) ❵ᵐ) ≡ getCoin deps + c
∪⁺singleton≡ {deps} {(dp , c)} = begin
getCoin (deps ∪⁺ ❴ (dp , c) ❵)
≡⟨ gc-hom deps ❴ (dp , c) ❵ ⟩
getCoin deps + getCoin{A = Deposits} ❴ (dp , c) ❵
≡⟨ cong (getCoin deps +_) (getCoin-singleton (dp , c)) ⟩
getCoin deps + c
∎
where open Prelude.≡-Reasoning
module _ {deposits : Deposits} {txid : TxId} {gaDep : Coin} where
≤updatePropDeps : (props : List GovProposal)
→ getCoin deposits ≤ getCoin (updateProposalDeposits props txid gaDep deposits)
≤updatePropDeps [] = ≤-reflexive refl
≤updatePropDeps (x ∷ props) = ≤-trans (≤updatePropDeps props)
(≤-trans (m≤m+n _ _)
(≤-reflexive $ sym $ ∪⁺singleton≡))
updatePropDeps≡ : (ps : List GovProposal)
→ getCoin (updateProposalDeposits ps txid gaDep deposits) - getCoin deposits ≡ (length ps) * gaDep
updatePropDeps≡ [] = n∸n≡0 (getCoin deposits)
updatePropDeps≡ (_ ∷ ps) = let
upD = updateProposalDeposits ps txid gaDep deposits in
begin
getCoin (upD ∪⁺ ❴ GovActionDeposit (txid , length ps) , gaDep ❵ᵐ) ∸ getCoin deposits
≡⟨ cong (_∸ getCoin deposits) ∪⁺singleton≡ ⟩
getCoin upD + gaDep ∸ getCoin deposits
≡⟨ +-∸-comm _ (≤updatePropDeps ps) ⟩
(getCoin upD ∸ getCoin deposits) + gaDep
≡⟨ cong (_+ gaDep) (updatePropDeps≡ ps) ⟩
(length ps) * gaDep + gaDep
≡⟨ +-comm ((length ps) * gaDep) gaDep ⟩
gaDep + (length ps) * gaDep
∎
where open Prelude.≡-Reasoning
≤certDeps : {d : Deposits} {(dp , c) : DepositPurpose × Coin}
→ getCoin d ≤ getCoin (d ∪⁺ ❴ (dp , c) ❵)
≤certDeps {d} = begin
getCoin d ≤⟨ m≤m+n (getCoin d) _ ⟩
getCoin d + _ ≡⟨ sym ∪⁺singleton≡ ⟩
getCoin (d ∪⁺ ❴ _ ❵) ∎
where open ≤-Reasoning
≤updateCertDeps : (cs : List DCert) {pp : PParams} {deposits : Deposits}
→ noRefundCert cs
→ getCoin deposits ≤ getCoin (updateCertDeposits pp cs deposits)
≤updateCertDeps [] nrf = ≤-reflexive refl
≤updateCertDeps (reg c v ∷ cs) {pp} {deposits} (_ All.∷ nrf) =
≤-trans ≤certDeps (≤updateCertDeps cs {pp} {deposits ∪⁺ ❴ CredentialDeposit c , pp .PParams.keyDeposit ❵} nrf)
≤updateCertDeps (delegate c _ _ v ∷ cs) {pp} {deposits} (_ All.∷ nrf) =
≤-trans ≤certDeps (≤updateCertDeps cs {pp} {deposits ∪⁺ ❴ CredentialDeposit c , v ❵} nrf)
≤updateCertDeps (regpool _ _ ∷ cs) (_ All.∷ nrf) = ≤-trans ≤certDeps (≤updateCertDeps cs nrf)
≤updateCertDeps (retirepool _ _ ∷ cs) (_ All.∷ nrf) = ≤updateCertDeps cs nrf
≤updateCertDeps (regdrep _ _ _ ∷ cs) (_ All.∷ nrf) = ≤-trans ≤certDeps (≤updateCertDeps cs nrf)
≤updateCertDeps (ccreghot _ _ ∷ cs) (_ All.∷ nrf) = ≤updateCertDeps cs nrf
Main Theorem: General Minimum Spending Condition
gmsc : let open Tx tx renaming (body to txb); open TxBody txb
pp = UTxOEnv.pparams Γ; open PParams pp
open UTxOState utxoState
renaming (utxo to st; fees to fs; deposits to deps; donations to dons)
in
Γ ⊢ ⟦ st , fs , deps , dons ⟧ ⇀⦇ tx ,UTXO⦈
⟦ utxo' , fees' , deposits' , donations' ⟧
→ noRefundCert txCerts -- FINAL ASSUMPTION --
-------------------------------------------------------------------
→ coin (consumed pp utxoState txb) ≥ length txGovProposals * govActionDeposit
gmsc step@(UTXO-inductive⋯ tx Γ utxoState _ _ _ _ _ _ c≡p cmint≡0 _ _ _ _ _ _ _ _ _ _) nrf =
begin
length txGovProposals * govActionDeposit
≡˘⟨ updatePropDeps≡ txGovProposals ⟩
getCoin (updateProposalDeposits txGovProposals txId govActionDeposit deps) ∸ getCoin deps
≤⟨ ∸-monoˡ-≤ (getCoin deps) (≤updateCertDeps txCerts nrf) ⟩
getCoin (updateDeposits pp txb deps) - getCoin deps
≡⟨ ∸≡posPart⊖ {getCoin (updateDeposits pp txb deps)} {getCoin deps} ⟩
newDeps
≤⟨ m≤n+m newDeps (coin balOut + txFee + txDonation) ⟩
coin balOut + txFee + txDonation + newDeps
≡⟨ +-assoc (coin balOut + txFee) txDonation newDeps ⟩
coin balOut + txFee + (txDonation + newDeps)
≡⟨ cong (coin balOut + txFee +_) (+-comm txDonation newDeps) ⟩
coin balOut + txFee + (newDeps + txDonation)
≡˘⟨ +-assoc (coin balOut + txFee) newDeps txDonation ⟩
coin balOut + txFee + newDeps + txDonation
≡˘⟨ cong (λ x → x + newDeps + txDonation) coin-inject-lemma ⟩
coin (balOut + inject txFee) + newDeps + txDonation
≡˘⟨ cong (_+ txDonation) coin-inject-lemma ⟩
coin (balOut + inject txFee + inject newDeps) + txDonation
≡˘⟨ coin-inject-lemma ⟩
coin (balOut + inject txFee + inject newDeps + inject txDonation)
≡˘⟨ cong coin c≡p ⟩
coin (balIn + mint + inject refunds + inject wdrls) ∎
where
open ≤-Reasoning
pp : PParams
pp = UTxOEnv.pparams Γ; open PParams pp
open Tx tx renaming (body to txb); open TxBody txb
open UTxOState utxoState renaming (utxo to st; fees to fs; deposits to deps; donations to dons)
newDeps refunds wdrls : Coin
newDeps = newDeposits pp utxoState txb
refunds = depositRefunds pp utxoState txb
wdrls = getCoin txWithdrawals
balIn balOut : Value
balIn = balance (st ∣ txIns)
balOut = balance (outs txb)