Skip to content

Commit d802bb5

Browse files
Merge pull request #973 from IntersectMBO/fd/reregistration-deposits
Don't count pool deposits when reregistering pools
2 parents 01b5bae + d01d094 commit d802bb5

File tree

9 files changed

+124
-31
lines changed

9 files changed

+124
-31
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### WIP
66

7+
- Do not count pool deposits a second time when reregistering pools
78
- Allow reregistration of pools in the POOL transition relation
89
- Implement the fPoolParams field of PState as in the Shelley specification
910
- Add the BBODY transition relation from Shelley

CONTRIBUTING.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ nix develop
225225

226226
# Build specific artifacts using fls-shake
227227
fls-shake html # Build HTML docs
228-
fls-shake hs # Build Haskell source
228+
rm -rf _build dist/hs; fls-shake hs # Build Haskell source
229229

230230
# See all available targets
231231
fls-shake --help
@@ -341,10 +341,10 @@ Then point your browser to <http://127.0.0.1:8000>.
341341
342342
For the best development experience, you should configure your IDE to use the Agda executable provided by this project's Nix environment.
343343
344-
First, build `agdaWithPackages` and create a stable symlink to it in your home directory. This prevents you from having to update your IDE settings every time the project's dependencies change.
344+
First, build `fls-agdaWithPackages` and create a stable symlink to it in your home directory. This prevents you from having to update your IDE settings every time the project's dependencies change.
345345
346346
```bash
347-
nix build ./#agdaWithPackages -o ~/ledger-agda
347+
nix build ./#fls-agdaWithPackages -o ~/ledger-agda
348348
```
349349

350350
Then make sure that the `~/ledger-agda/bin` directory is in your `PATH` when starting your editor.
@@ -701,6 +701,27 @@ See [the `conformance-example` directory][conformance-example].
701701
## 🗃️ Miscellanea
702702
703703
704+
### Updating Agda dependencies in the Nix configuration
705+
706+
The following example ilustrates the procedure
707+
708+
```
709+
nix flake update agda-nix/abstract-set-theory \
710+
--override-input agda-nix/abstract-set-theory \
711+
github:input-output-hk/agda-sets/bbaa00abc4aef061896ae5d3cdec148bfbf5029f
712+
nix build ./#fls-agdaWithPackages -o ~/ledger-agda
713+
```
714+
715+
The first line updates the commit hash to use for a dependency. In the example,
716+
it updates the dependency `agda-nix/abstract-set-theory` to point at the commit
717+
`bbaa00abc4aef061896ae5d3cdec148bfbf5029f` or the repository
718+
`github:input-output-hk/agda-sets`.
719+
720+
The second line rebuilds the Agda mode to use with emacs. This step is necessary
721+
for emacs to use the new version of the dependency when loading Agda code. This
722+
assumes that `~/ledger-agda/bin` is in your `PATH`.
723+
724+
704725
### Plotting typechecking times
705726
706727
The script `scripts/plot_typecheck_time.py` can be used to generate an `html`

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Ledger/Conway/Conformance/Equivalence/Deposits.agda

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ module Ledger.Conway.Conformance.Equivalence.Deposits
1616
(txs : _) (open TransactionStructure txs)
1717
(abs : AbstractFunctions txs) (open AbstractFunctions abs)
1818
where
19-
19+
2020
private
2121
module L where
2222
open import Ledger.Conway.Specification.Ledger txs abs public
2323
open import Ledger.Conway.Specification.Utxo txs abs public
2424
open import Ledger.Conway.Specification.Certs govStructure public
25-
25+
2626
module C where
2727
open import Ledger.Conway.Conformance.Ledger txs abs public
2828
open import Ledger.Conway.Conformance.Utxo txs abs public
@@ -118,8 +118,8 @@ cong-certGDeps = cong-filterᵐ
118118
castValidDepsᵈ : {pp deps₁ deps₂ certs} deps₁ ≡ᵐ deps₂ ValidDepsᵈ pp deps₁ certs ValidDepsᵈ pp deps₂ certs
119119
castValidDepsᵈ eq [] = []
120120
castValidDepsᵈ {pp} {certs = cert ∷ _} eq (delegate deps) = delegate (castValidDepsᵈ (cong-updateCertDeposit pp cert eq) deps)
121-
castValidDepsᵈ {pp} {deps₁} {deps₂} {certs = cert ∷ _} eq (dereg h h' deps) =
122-
dereg (proj₁ eq h) h'
121+
castValidDepsᵈ {pp} {deps₁} {deps₂} {certs = cert ∷ _} eq (dereg h h' deps) =
122+
dereg (proj₁ eq h) h'
123123
(castValidDepsᵈ (cong-updateCertDeposit pp cert {deps₁} {deps₂} eq) deps)
124124
--castValidDepsᵈ {pp} {deps₁} {deps₂}
125125
-- {certs = cert ∷ _} eq (dereg h deps) = dereg (map₂ (proj₁ eq) h) (castValidDepsᵈ (cong-updateCertDeposit
@@ -292,8 +292,8 @@ lem-upd-cert-ddeps {pp} deps (L.reg c v ∷ certs) =
292292
lem-upd-cert-ddeps (deps ∪⁺ dep) certs
293293
where dep = ❴ L.CredentialDeposit c , pp .PParams.keyDeposit ❵
294294
lem-upd-cert-ddeps {pp} deps (L.regpool kh p ∷ certs) =
295-
≈-sym (cong-updateDDeps certs (lem-add-excluded λ ())) ⟨≈⟩
296-
lem-upd-cert-ddeps (deps ∪ dep) certs
295+
≈-sym (cong-updateDDeps certs (lem-add-excluded-∪ˡ deps λ ())) ⟨≈⟩
296+
lem-upd-cert-ddeps (deps ∪ˡ dep) certs
297297
where dep = ❴ L.PoolDeposit kh , pp .PParams.poolDeposit ❵
298298
lem-upd-cert-ddeps {pp} deps (L.regdrep c v a ∷ certs) =
299299
≈-sym (cong-updateDDeps certs (lem-add-excluded λ ())) ⟨≈⟩
@@ -322,8 +322,8 @@ lem-upd-cert-gdeps {pp} deps (L.reg c v ∷ certs) =
322322
lem-upd-cert-gdeps (deps ∪⁺ dep) certs
323323
where dep = ❴ L.CredentialDeposit c , pp .PParams.keyDeposit ❵
324324
lem-upd-cert-gdeps {pp} deps (L.regpool kh p ∷ certs) =
325-
≈-sym (cong-updateGDeps certs (lem-add-excluded λ ())) ⟨≈⟩
326-
lem-upd-cert-gdeps (deps ∪ dep) certs
325+
≈-sym (cong-updateGDeps certs (lem-add-excluded-∪ˡ deps λ ())) ⟨≈⟩
326+
lem-upd-cert-gdeps (deps ∪ˡ dep) certs
327327
where dep = ❴ L.PoolDeposit kh , pp .PParams.poolDeposit ❵
328328
lem-upd-cert-gdeps {pp} deps (L.regdrep c v a ∷ certs) =
329329
≈-sym (cong-updateGDeps certs (lem-add-included DRepDeposit)) ⟨≈⟩

src/Ledger/Conway/Conformance/Equivalence/Map.agda

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
module Ledger.Conway.Conformance.Equivalence.Map where
44

5-
open import Ledger.Prelude
5+
open import Ledger.Prelude hiding (filterᵐ-singleton-false)
66
open import Axiom.Set.Properties th
7-
open import Axiom.Set.Map.Dec
87

98
import Algebra as Alg
109
import Algebra.Definitions as AlgDefs
@@ -614,6 +613,8 @@ module _ {A B : Type}
614613
filterᵐ-singleton-true p .proj₁ = proj₂ ∘ (from ∈-filter)
615614
filterᵐ-singleton-true {k}{v} p .proj₂ {a} x = to ∈-filter (subst P′ (sym (from ∈-singleton x)) p , x)
616615

616+
-- TODO: move to agda-sets
617+
-- https://github.com/input-output-hk/agda-sets/pull/19
617618
filterᵐ-singleton-false : ¬ P k filterᵐ P′ ❴ k , v ❵ ≡ᵐ ∅
618619
filterᵐ-singleton-false ¬p .proj₁ x =
619620
⊥-elim $ ¬p $ subst P′ (from ∈-singleton $ proj₂ (from ∈-filter x)) (proj₁ $ from ∈-filter x)
@@ -656,5 +657,33 @@ module _ {A B : Type}
656657
lem-add-excluded p =
657658
filterᵐ-∪⁺-distr _ _ ⟨≈⟩ ∪⁺-cong-l (filterᵐ-singleton-false p) ⟨≈⟩ ∪⁺-id-r _
658659

660+
-- TODO: move to agda-sets
661+
-- https://github.com/input-output-hk/agda-sets/pull/19
662+
lem-add-excluded-∪ˡ
663+
: (m : A ⇀ B)
664+
¬ P k
665+
filterᵐ P′ (m ∪ˡ ❴ k , v ❵) ≡ᵐ filterᵐ P′ m
666+
lem-add-excluded-∪ˡ {k = k} {v = v} m ¬p with k ∈? dom m
667+
... | yes k∈m =
668+
filterᵐ-cong
669+
{m = m ∪ˡ ❴ k , v ❵}
670+
{m' = m}
671+
(singleton-∈-∪ˡ {m = m} k∈m)
672+
... | no k∉m = begin
673+
filterᵐ P′ (m ∪ˡ ❴ k , v ❵) ˢ
674+
≈⟨ filter-cong $ disjoint-∪ˡ-∪ (disjoint-sing k∉m) ⟩
675+
filterˢ P′ (m ˢ ∪ ❴ k , v ❵)
676+
≈⟨ filter-hom-∪ ⟩
677+
filterˢ P′ (m ˢ) ∪ filterˢ P′ ❴ k , v ❵
678+
≈⟨ ∪-cong ≡ᵉ.refl (filterᵐ-singleton-false ¬p) ⟩
679+
filterˢ P′ (m ˢ) ∪ ∅
680+
≈⟨ ∪-identityʳ (filterˢ P′ (m ˢ)) ⟩
681+
filterˢ P′ (m ˢ)
682+
683+
where
684+
disjoint-sing : k ∉ dom m disjoint (dom m) (dom (singleton (k , v)))
685+
disjoint-sing k∉m a∈d a∈sing
686+
rewrite from ∈-dom-singleton-pair a∈sing = k∉m a∈d
687+
659688
lem-del-excluded : m ¬ P k filterᵐ P′ (m ∣ ❴ k ❵ ᶜ) ≡ᵐ filterᵐ P′ m
660689
lem-del-excluded m ¬p = filterᵐ-restrict m ⟨≈⟩ restrict-singleton-filterᵐ-false m ¬p

src/Ledger/Conway/Specification/Epoch/Properties/GovDepsMatch.lagda.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ For the formal statement of the lemma,
9696
*Proof*.
9797

9898
```agda
99-
EPOCH-govDepsMatch {eps'} {e} ratify-removed (EPOCH (x , POOLREAP , _)) =
100-
poolReapMatch ∘ ratifiesSnapMatch
99+
EPOCH-govDepsMatch {eps'} {e} ratify-removed = mainProof
101100
where
102101
103102
-- the combinator used in the EPOCH rule
@@ -200,11 +199,6 @@ For the formal statement of the lemma,
200199
res-dom d∈res -- d ∈ retiredDeposits
201200
where import Data.Product.Base as Product using (map₂)
202201
203-
ratifiesSnapMatch : govDepsMatch (LStateOf eps) → govDepsMatch ls₁
204-
ratifiesSnapMatch =
205-
≡ᵉ.trans (filter-cong $ dom-cong (res-comp-cong $ ≡ᵉ.sym ΔΠ'≡ΔΠ))
206-
∘ from ≡ᵉ⇔≡ᵉ' ∘ main-invariance-lemma ∘ to ≡ᵉ⇔≡ᵉ'
207-
208202
noGADepositIsRetired
209203
: (d : DepositPurpose)
210204
→ d ∈ dom (DepositsOf ls₁ ∣ retiredDeposits)
@@ -271,7 +265,18 @@ For the formal statement of the lemma,
271265
open import Relation.Binary using (IsEquivalence)
272266
import Axiom.Set.Rel th as Rel
273267
274-
poolReapMatch : govDepsMatch ls₁ → govDepsMatch (LStateOf eps')
275-
poolReapMatch = ≡ᵉ.trans dropRetiredDeposits
268+
mainProof
269+
: _ ⊢ eps ⇀⦇ e ,EPOCH⦈ eps'
270+
→ govDepsMatch (LStateOf eps) → govDepsMatch (LStateOf eps')
271+
-- Pattern matching POOLREAP used to be done in EPOCH-govDepsMatch directly.
272+
-- However, that made typechecking much slower.
273+
mainProof (EPOCH (x , POOLREAP , _)) = poolReapMatch ∘ ratifiesSnapMatch
274+
where
275+
ratifiesSnapMatch : govDepsMatch (LStateOf eps) → govDepsMatch ls₁
276+
ratifiesSnapMatch =
277+
≡ᵉ.trans (filter-cong $ dom-cong (res-comp-cong $ ≡ᵉ.sym ΔΠ'≡ΔΠ))
278+
∘ from ≡ᵉ⇔≡ᵉ' ∘ main-invariance-lemma ∘ to ≡ᵉ⇔≡ᵉ'
276279
280+
poolReapMatch : govDepsMatch ls₁ → govDepsMatch (LStateOf eps')
281+
poolReapMatch = ≡ᵉ.trans dropRetiredDeposits
277282
```

src/Ledger/Conway/Specification/Ledger/Properties/Base.lagda.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ module LEDGER-PROPS (tx : Tx) (Γ : LEnv) (s : LState) where
113113
dpMap-rmOrphanDRepVotes : ∀ certState govSt → dpMap (rmOrphanDRepVotes certState govSt) ≡ dpMap govSt
114114
dpMap-rmOrphanDRepVotes certState govSt = sym (fmap-∘ govSt) -- map proj₁ ∘ map (map₂ _) ≡ map (proj₁ ∘ map₂ _) ≡ map proj₁
115115
116+
116117
module SetoidProperties (tx : Tx) (Γ : LEnv) (s : LState) where
117118
open Tx tx renaming (body to txb); open TxBody txb
118119
open LEnv Γ renaming (pparams to pp)
@@ -191,8 +192,8 @@ module SetoidProperties (tx : Tx) (Γ : LEnv) (s : LState) where
191192
cd = certDeposit dcert pp
192193
filter0 = filterCD dcert deps
193194
noGACerts (dcert@(regpool _ _) ∷ cs) deps = begin
194-
filterˢ isGADeposit (dom (updateCertDeposits pp cs (deps ∪ cd))) ≈⟨ noGACerts cs _ ⟩
195-
filterˢ isGADeposit (dom (deps ∪ cd)) ≈⟨ filter-cong dom∪≡∪dom ⟩
195+
filterˢ isGADeposit (dom (updateCertDeposits pp cs (deps ∪ˡ cd))) ≈⟨ noGACerts cs _ ⟩
196+
filterˢ isGADeposit (dom (deps ∪ˡ cd)) ≈⟨ filter-cong (dom∪ˡ≡∪dom {m = deps} {m' = cd})
196197
filterˢ isGADeposit (dom deps ∪ dom (cd ˢ )) ≈⟨ filter-hom-∪ ⟩
197198
filterˢ isGADeposit (dom deps) ∪ filterˢ isGADeposit (dom (cd ˢ)) ≈⟨ ∪-cong ≡ᵉ.refl filter0 ⟩
198199
filterˢ isGADeposit (dom deps) ∪ ∅ ≈⟨ ∪-identityʳ $ filterˢ isGADeposit (dom deps) ⟩

src/Ledger/Conway/Specification/Utxo.lagda.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ updateCertDeposits pp (reg c v ∷ certs) deposits
319319
updateCertDeposits pp (delegate c vd khs v ∷ certs) deposits
320320
= updateCertDeposits pp certs (deposits ∪⁺ certDeposit (delegate c vd khs v) pp)
321321
updateCertDeposits pp (regpool kh p ∷ certs) deposits
322-
= updateCertDeposits pp certs (deposits ∪⁺ certDeposit (regpool kh p) pp)
322+
-- pool deposits are not added a second time if they are already present
323+
-- (reregistrations or duplicate certificates).
324+
= updateCertDeposits pp certs (deposits ∪ˡ certDeposit (regpool kh p) pp)
323325
updateCertDeposits pp (regdrep c v a ∷ certs) deposits
324326
= updateCertDeposits pp certs (deposits ∪⁺ certDeposit (regdrep c v a) pp)
325327
updateCertDeposits pp (dereg c v ∷ certs) deposits

src/Ledger/Conway/Specification/Utxo/Properties/GenMinSpend.lagda.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,41 @@ module _ -- ASSUMPTION --
104104
where open ≤-Reasoning
105105
106106
107+
≤certDeps∪ˡ : {d : Deposits} {(dp , c) : DepositPurpose × Coin}
108+
→ getCoin d ≤ getCoin (d ∪ˡ ❴ (dp , c) ❵)
109+
110+
≤certDeps∪ˡ {d} {dp , c} with dp ∈? dom d
111+
... | yes dp∈ =
112+
from ≤⇔<∨≈ $ inj₂ $
113+
indexedSumᵛ'-cong {C = Coin} {x = d} {y = d ∪ˡ ❴ dp , c ❵} $
114+
begin
115+
d ˢ ≈⟨ ≡ᵉ.sym $ singleton-∈-∪ˡ {m = d} dp∈ ⟩
116+
(d ∪ˡ ❴ (dp , c) ❵) ˢ
117+
118+
where
119+
open import Relation.Binary.Structures using (IsEquivalence; IsPreorder)
120+
open import Relation.Binary.Reasoning.Setoid (≡ᵉ-Setoid {A = DepositPurpose × Coin})
121+
module ≡ᵉ = IsEquivalence ≡ᵉ-isEquivalence
122+
123+
... | no ¬p = begin
124+
getCoin d ≤⟨ m≤m+n (getCoin d) _ ⟩
125+
getCoin d + _ ≡⟨ sym $ indexedSumᵐ-∪
126+
{X = d ᶠᵐ}
127+
{Y = ❴ dp , c ❵ ᶠᵐ}
128+
{f = proj₂}
129+
(disjoint-sing ¬p)
130+
131+
indexedSumᵐ proj₂ ((d ᶠᵐ) ∪ˡᶠ (❴ dp , c ❵ ᶠᵐ))
132+
≡⟨ sym $ indexedSumᵐ-∪ˡ-∪ˡᶠ {B = ⊤} d ❴ dp , c ❵ ⟩
133+
getCoin (d ∪ˡ ❴ dp , c ❵)
134+
135+
where
136+
open ≤-Reasoning
137+
138+
disjoint-sing : dp ∉ dom d → disjoint (dom d) (dom ❴ dp , c ❵ˢ)
139+
disjoint-sing dp∉d a∈d a∈sing
140+
rewrite from ∈-dom-singleton-pair a∈sing = dp∉d a∈d
141+
107142
≤updateCertDeps : (cs : List DCert) {pp : PParams} {deposits : Deposits}
108143
→ noRefundCert cs
109144
→ getCoin deposits ≤ getCoin (updateCertDeposits pp cs deposits)
@@ -112,7 +147,8 @@ module _ -- ASSUMPTION --
112147
≤-trans ≤certDeps (≤updateCertDeps cs {pp} {deposits ∪⁺ ❴ CredentialDeposit c , pp .PParams.keyDeposit ❵} nrf)
113148
≤updateCertDeps (delegate c _ _ v ∷ cs) {pp} {deposits} (_ All.∷ nrf) =
114149
≤-trans ≤certDeps (≤updateCertDeps cs {pp} {deposits ∪⁺ ❴ CredentialDeposit c , v ❵} nrf)
115-
≤updateCertDeps (regpool _ _ ∷ cs) (_ All.∷ nrf) = ≤-trans ≤certDeps (≤updateCertDeps cs nrf)
150+
≤updateCertDeps (regpool _ _ ∷ cs) {_} {deposits} (_ All.∷ nrf) =
151+
≤-trans (≤certDeps∪ˡ {d = deposits}) (≤updateCertDeps cs nrf)
116152
≤updateCertDeps (retirepool _ _ ∷ cs) (_ All.∷ nrf) = ≤updateCertDeps cs nrf
117153
≤updateCertDeps (regdrep _ _ _ ∷ cs) (_ All.∷ nrf) = ≤-trans ≤certDeps (≤updateCertDeps cs nrf)
118154
≤updateCertDeps (ccreghot _ _ ∷ cs) (_ All.∷ nrf) = ≤updateCertDeps cs nrf
@@ -188,5 +224,3 @@ module _ -- ASSUMPTION --
188224
balIn = balance (st ∣ txIns)
189225
balOut = balance (outs txb)
190226
```
191-
192-

0 commit comments

Comments
 (0)