Skip to content

Commit ae36396

Browse files
authored
[Dijkstra] Ledger PoV: import the proved gov-deposit facts, dropping their parameters
rmOrphanDRepVotes-coinFromGovDeposit and GOVS-coinFromGovDeposit are theorems on this branch, so LEDGER-PoV now imports Gov.Properties.PoV instead of assuming them. proposalsOf and proposalsOf-Proposals+Votes now have their single home in Gov.Properties.PoV; the consumer's copies are deleted. AI-assisted development: Claude Fable 5 (Anthropic)
1 parent 10b00b4 commit ae36396

2 files changed

Lines changed: 21 additions & 54 deletions

File tree

src/Ledger/Dijkstra/Specification/Gov/Properties/PoV.lagda.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ source_path: src/Ledger/Dijkstra/Specification/Gov/Properties/PoV.lagda.md
77

88
This module proves the two governance-deposit accounting facts that the top-level
99
preservation-of-value proof (`LEDGER-pov`{.AgdaFunction} in
10-
`Ledger.Properties.PoV`{.AgdaModule}) assumes as module parameters:
10+
`Ledger.Properties.PoV`{.AgdaModule}) consumes:
1111

1212
+ `rmOrphanDRepVotes-coinFromGovDeposit`{.AgdaFunction}:
1313
`rmOrphanDRepVotes`{.AgdaFunction} only rewrites the `gvDRep`{.AgdaField} votes of
@@ -21,8 +21,8 @@ preservation-of-value proof (`LEDGER-pov`{.AgdaFunction} in
2121
for the new action, and `GOV-Vote`{.AgdaInductiveConstructor} never changes a
2222
deposit.
2323

24-
Their statements match the corresponding `LEDGER-PoV`{.AgdaModule} module
25-
parameters (modulo this module's own `proposalsOf`{.AgdaFunction} copy; see below).
24+
`Ledger.Properties.PoV`{.AgdaModule} imports both facts, together with
25+
`proposalsOf`{.AgdaFunction} and its extraction lemma (see below).
2626

2727
<!--
2828
```agda
@@ -55,11 +55,9 @@ open import Interface.STS
5555

5656
The right injections of a list of sums, used (at `GovVote ⊎ GovProposal`) to extract
5757
the proposals from a mixed `GOVS`{.AgdaDatatype} signal list.
58-
`Ledger.Properties.PoV`{.AgdaModule} defines an identical function for stating its
59-
`GOVS-coinFromGovDeposit`{.AgdaFunction} parameter, but importing it here would
60-
create an import cycle once `Ledger.Properties.PoV`{.AgdaModule} is rewired to
61-
import *this* module. So we keep a local copy (clause-for-clause identical),
62-
together with the `proposalsOf-Proposals+Votes`{.AgdaFunction} extraction lemma.
58+
`Ledger.Properties.PoV`{.AgdaModule} imports this module, so
59+
`proposalsOf`{.AgdaFunction} lives here, together with the
60+
`proposalsOf-Proposals+Votes`{.AgdaFunction} extraction lemma.
6361

6462
```agda
6563
proposalsOf : ∀ {A B : Type} → List (A ⊎ B) → List B
@@ -241,8 +239,8 @@ GOVSᵢ-coinFromGovDeposit {Γ} {s = s} (BS-ind {sigs = sigs} (GOV-Propose _) re
241239
dep = PParams.govActionDeposit (PParamsOf Γ)
242240
```
243241

244-
Specializing to index `0` gives the statement in the shape of the
245-
`LEDGER-PoV`{.AgdaModule} module parameter:
242+
Specializing to index `0` gives the statement in the shape that
243+
`LEDGER-PoV`{.AgdaModule} consumes:
246244

247245
```agda
248246
GOVS-coinFromGovDeposit :

src/Ledger/Dijkstra/Specification/Ledger/Properties/PoV.lagda.md

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ open import Ledger.Dijkstra.Specification.Utxow txs abs
113113
114114
open import Ledger.Dijkstra.Specification.Certs.Properties.PoV govStructure
115115
open import Ledger.Dijkstra.Specification.Entities.Properties.PoV txs
116+
open import Ledger.Dijkstra.Specification.Gov.Properties.PoV txs abs
117+
using ( proposalsOf; proposalsOf-Proposals+Votes
118+
; rmOrphanDRepVotes-coinFromGovDeposit; GOVS-coinFromGovDeposit )
116119
open import Ledger.Dijkstra.Specification.Utxo.Properties.PoV txs abs
117120
using (noMintingSubTxs)
118121
open import Ledger.Dijkstra.Specification.Utxow.Properties.PoV txs abs
@@ -126,13 +129,6 @@ open ≡-Reasoning
126129
instance
127130
_ = +-0-monoid
128131
129-
-- proposalsOf is useful for extracting proposals from a mixed `GOVS` (`GovVote ⊎
130-
-- GovProposal`) input list for the `GOVS-coinFromGovDeposit` gov-deposit accounting.
131-
proposalsOf : {A B : Type} → List (A ⊎ B) → List B
132-
proposalsOf [] = []
133-
proposalsOf (inj₁ _ ∷ xs) = proposalsOf xs
134-
proposalsOf (inj₂ p ∷ xs) = p ∷ proposalsOf xs
135-
136132
```
137133
-->
138134

@@ -155,8 +151,8 @@ organized into the following groups:
155151
themselves are imported from `Utxow.Properties.PoV`{.AgdaModule};
156152
+ Cert facts: value accounting for a single `CERTS`{.AgdaDatatype} run,
157153
imported from `Certs.Properties.PoV`{.AgdaModule};
158-
+ Gov deposit facts (`rmOrphanDRepVotes-coinFromGovDeposit`{.AgdaFunction},
159-
`GOVS-coinFromGovDeposit`{.AgdaFunction});
154+
+ Gov deposit facts, imported from `Gov.Properties.PoV`{.AgdaModule} together
155+
with `proposalsOf`{.AgdaFunction}, whose single home is that module;
160156
+ no-truncation withdrawal bounds (`ENTITIES-wdrls-bounded`{.AgdaFunction},
161157
`SUBENTITIES-wdrls-bounded`{.AgdaFunction}); see
162158
`Entities.Properties.PoV`{.AgdaModule} for why these are not consequences of
@@ -222,28 +218,15 @@ module LEDGER-PoV
222218
→ Γe ⊢ cs ⇀⦇ stx ,SUBENTITIES⦈ cs'
223219
→ ∀[ (addr , amt) ∈ (WithdrawalsOf stx) ˢ ]
224220
amt ≤ maybe id 0 (lookupᵐ? (RewardsOf cs) (stake addr)) )
225-
226-
-- Governance-deposit accounting. `rmOrphanDRepVotes` only rewrites
227-
-- `votes.gvDRep`, never `GovActionState.deposit`, so it leaves
228-
-- `coinFromGovDeposit` unchanged.
229-
( rmOrphanDRepVotes-coinFromGovDeposit :
230-
(cs : CertState) (g : GovState)
231-
→ coinFromGovDeposit (rmOrphanDRepVotes cs g) ≡ coinFromGovDeposit g )
232-
233-
-- Per-`GOVS`-step gov-deposit growth equals `govProposalsDeposits` of step's
234-
-- proposals. Used by `SUBLEDGERS-gov-coin` and `gov-acc`.
235-
( GOVS-coinFromGovDeposit :
236-
∀ {Γ : GovEnv} {govSt govSt′ : GovState} {props}
237-
→ Γ ⊢ govSt ⇀⦇ props ,GOVS⦈ govSt′
238-
→ coinFromGovDeposit govSt′
239-
≡ coinFromGovDeposit govSt + govProposalsDeposits (PParamsOf Γ) (proposalsOf props) )
240221
where
241222
242-
-- The UTxO-side and Certs-side facts, previously module parameters, are now
243-
-- imported: `utxow-pov-invalid`, `UTXOW-V-mechanical` and
223+
-- The UTxO-side, Certs-side and gov-side facts, previously module parameters,
224+
-- are now imported: `utxow-pov-invalid`, `UTXOW-V-mechanical` and
244225
-- `UTXOW-batch-balance-coin` from `UTXOW-PoV`; `subutxow-step-coin` from
245-
-- `SUBUTXOW-PoV` (given the two batch-threading hypotheses above); and the
246-
-- `CERTS-*` facts with `refundCertDeposits-++` from `Certs.Properties.PoV`.
226+
-- `SUBUTXOW-PoV` (given the two batch-threading hypotheses above); the
227+
-- `CERTS-*` facts with `refundCertDeposits-++` from `Certs.Properties.PoV`;
228+
-- and `rmOrphanDRepVotes-coinFromGovDeposit` with `GOVS-coinFromGovDeposit`
229+
-- from `Gov.Properties.PoV`.
247230
open UTXOW-PoV tx noMintSubTx
248231
open SUBUTXOW-PoV subtx-fresh-txid subtx-spend-agree
249232
@@ -554,24 +537,10 @@ transaction's certificates.
554537
Induct over `SUBLEDGERS`{.AgdaDatatype}, threading the per-`GOVS` gov-deposit growth: each
555538
`SUBLEDGER-V`{.AgdaInductiveConstructor} step grows `coinFromGovDeposit`{.AgdaFunction} by the
556539
`govProposalsDeposits`{.AgdaFunction} of the sub-transaction's proposals (via the
557-
`GOVS-coinFromGovDeposit`{.AgdaFunction} parameter applied to the step's `GOVS`
540+
`GOVS-coinFromGovDeposit`{.AgdaFunction} fact applied to the step's `GOVS`
558541
premise). `SUBLEDGER-I`{.AgdaInductiveConstructor} is ruled out by the top-level validity flag.
559542

560543
```agda
561-
-- `proposalsOf (GovProposals+Votes t)` recovers exactly the proposals of `t`.
562-
proposalsOf-Proposals+Votes : ∀ {ℓ} (t : Tx ℓ)
563-
→ proposalsOf (GovProposals+Votes t) ≡ ListOfGovProposalsOf t
564-
proposalsOf-Proposals+Votes t = go (ListOfGovProposalsOf t) (ListOfGovVotesOf t)
565-
where
566-
drop-votes : {A B : Type} (vs : List A) → proposalsOf {B = B} (map inj₁ vs) ≡ []
567-
drop-votes [] = refl
568-
drop-votes (_ ∷ vs) = drop-votes vs
569-
570-
go : {A B : Type} (ps : List B) (vs : List A)
571-
→ proposalsOf (map inj₂ ps ++ map inj₁ vs) ≡ ps
572-
go [] vs = drop-votes vs
573-
go (p ∷ ps) vs = cong (p ∷_) (go ps vs)
574-
575544
open SubLedgerEnv
576545
577546
SUBLEDGERS-gov-coin :
@@ -653,7 +622,7 @@ sub-level totals of direct deposits and withdrawals respectively, the goal
653622
where `G₀ = coinFromGovDeposit govState₀` and, since the final
654623
`LEDGER-V`{.AgdaInductiveConstructor} `GovState`{.AgdaRecord}
655624
is `rmOrphanDRepVotes certState₂ govState₂` and `rmOrphanDRepVotes` preserves
656-
`coinFromGovDeposit` (parameter `rmOrphanDRepVotes-coinFromGovDeposit`),
625+
`coinFromGovDeposit` (`rmOrphanDRepVotes-coinFromGovDeposit`),
657626
`G' = coinFromGovDeposit govState₂`.
658627

659628
The body assembles the goal from two lemmas:

0 commit comments

Comments
 (0)