Skip to content

Commit 899ab97

Browse files
committed
Synchronize local copy of the Ledger stuff to include latest changes
1 parent 242f513 commit 899ab97

File tree

12 files changed

+138
-50
lines changed

12 files changed

+138
-50
lines changed

docs/agda-spec/src/Axiom/Set.agda

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ record Theory {ℓ} : Type (sucˡ ℓ) where
9797
finite : Set A Type ℓ
9898
finite X = ∃[ l ] {a} a ∈ X ⇔ a ∈ˡ l
9999

100+
Show-finite : ⦃ Show A ⦄ Show (Σ (Set A) finite)
101+
Show.show Show-finite (X , (l , _)) = Show-List .show l
102+
100103
weakly-finite : Set A Type ℓ
101104
weakly-finite X = ∃[ l ] {a} a ∈ X a ∈ˡ l
102105

@@ -291,6 +294,11 @@ record Theoryᶠ : Type₁ where
291294
lengthˢ : ⦃ DecEq A ⦄ Set A
292295
lengthˢ X = card (X , DecEq⇒strongly-finite X)
293296

297+
module _ {A : Type} ⦃ _ : Show A ⦄ where
298+
instance
299+
Show-Set : Show (Set A)
300+
Show-Set .show = λ x Show-finite .show (x , (finiteness x))
301+
294302
-- set theories with an infinite set (containing all natural numbers)
295303
record Theoryⁱ : Type₁ where
296304
field theory : Theory
@@ -307,30 +315,32 @@ record Theoryᵈ : Type₁ where
307315
field
308316
∈-sp : ⦃ DecEq A ⦄ spec-∈ A
309317
_∈?_ : ⦃ DecEq A ⦄ Decidable² (_∈_ {A = A})
310-
all? : ⦃ DecEq A ⦄ {P : A Type} (P? : Decidable¹ P) {X : Set A} Dec (All P X)
311-
any? : ⦃ DecEq A ⦄ {P : A Type} (P? : Decidable¹ P) (X : Set A) Dec (Any P X)
312-
313-
module _ {A : Type} ⦃ _ : DecEq A ⦄ where
318+
all? : {P : A Type} (P? : Decidable¹ P) {X : Set A} Dec (All P X)
319+
any? : {P : A Type} (P? : Decidable¹ P) (X : Set A) Dec (Any P X)
314320

315-
_∈ᵇ_ : A Set A Bool
316-
a ∈ᵇ X = ⌊ a ∈? X ⌋
317-
318-
instance
319-
Dec-∈ : _∈_ {A = A} ⁇²
320-
Dec-∈ = ⁇² _∈?_
321321

322-
module _ {P : A Type} ⦃ _ : P ⁇¹ ⦄ where instance
322+
module _ {A : Type} {P : A Type} where
323+
module _ ⦃ _ : P ⁇¹ ⦄ where instance
323324
Dec-Allˢ : All P ⁇¹
324325
Dec-Allˢ = ⁇¹ λ x all? dec¹ {x}
325326

326327
Dec-Anyˢ : Any P ⁇¹
327328
Dec-Anyˢ = ⁇¹ any? dec¹
328329

329-
module _ {P : A Type} (P? : Decidable¹ P) where
330+
module _ (P? : Decidable¹ P) where
330331
allᵇ anyᵇ : (X : Set A) Bool
331332
allᵇ X = ⌊ all? P? {X} ⌋
332333
anyᵇ X = ⌊ any? P? X ⌋
333334

335+
module _ {A : Type} ⦃ _ : DecEq A ⦄ where
336+
337+
_∈ᵇ_ : A Set A Bool
338+
a ∈ᵇ X = ⌊ a ∈? X ⌋
339+
340+
instance
341+
Dec-∈ : _∈_ {A = A} ⁇²
342+
Dec-∈ = ⁇² _∈?_
343+
334344
_ = _∈_ {A = A} ⁇² ∋ it
335345
_ = _⊆_ {A = A} ⁇² ∋ it
336346
_ = _≡ᵉ_ {A = A} ⁇² ∋ it

docs/agda-spec/src/Axiom/Set/Map.agda

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ mapPartial-uniq {f = f} prop {a} {b} {b'} p q =
289289
mapMaybeWithKeyᵐ : (A B Maybe B') Map A B Map A B'
290290
mapMaybeWithKeyᵐ f (rel , prop) = mapMaybeWithKey f rel , mapPartial-uniq {f = f} prop
291291

292+
mapFromPartialFun : (A Maybe B) Set A Map A B
293+
mapFromPartialFun f s = mapMaybeWithKeyᵐ (λ _ f) (idMap s)
294+
292295
module Restrictionᵐ (sp-∈ : spec-∈ A) where
293296
private module R = Restriction sp-∈
294297
open Unionᵐ sp-∈

docs/agda-spec/src/Interface/ComputationalRelation.agda

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,14 @@ module _ {STS : C → S → Sig → S → Type} (comp comp' : Computational STS
161161
compute-ext≡ = ExtendedRel-rightUnique comp
162162
(ExtendedRel-compute comp) (ExtendedRel-compute comp')
163163

164-
Computational⇒Dec' :
165-
⦃ _ : DecEq S ⦄ {STS : C S Sig S Type} ⦃ comp : Computational STS Err ⦄
166-
Dec (STS c s sig s')
167-
Computational⇒Dec' ⦃ comp = comp ⦄ = Computational⇒Dec comp
168-
169164
open Computational ⦃...⦄
170165

166+
Computational⇒Dec' :
167+
{STS : C S Sig S Type} ⦃ comp : Computational STS Err ⦄ Dec (∃[ s' ] STS c s sig s')
168+
Computational⇒Dec' with computeProof _ _ _ in eq
169+
... | success x = yes x
170+
... | failure x = no λ (_ , h) failure⇒∀¬STS (-, cong (map proj₁) eq) _ h
171+
171172
record InjectError Err₁ Err₂ : Type where
172173
field injectError : Err₁ Err₂
173174

docs/agda-spec/src/Interface/HasAdd/Instance.agda

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ module Interface.HasAdd.Instance where
44
open import Interface.HasAdd
55
open import Data.Integer as ℤ using (ℤ)
66
open import Data.Nat as ℕ using (ℕ)
7+
open import Data.String as Str
78

89
instance
910
addInt : HasAdd ℤ
1011
addInt ._+_ = ℤ._+_
1112

1213
addNat : HasAdd ℕ
1314
addNat ._+_ = ℕ._+_
15+
16+
addString : HasAdd String
17+
addString ._+_ = Str._++_

docs/agda-spec/src/Interface/IsSet.agda

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ All-syntax : ∀ {A X} ⦃ _ : IsSet X A ⦄ → (A → Type) → X → Type
3131
All-syntax P X = All P (toSet X)
3232
syntax All-syntax (λ x P) l = ∀[ x ∈ l ] P
3333

34+
infix 2 Ex-syntax
35+
Ex-syntax : {A X} ⦃ _ : IsSet X A ⦄ (A Type) X Type
36+
Ex-syntax P X = Any P (toSet X)
37+
syntax Ex-syntax (λ x P) l = ∃[ x ∈ l ] P
38+
3439
module _ ⦃ _ : IsSet X (A × B) ⦄ where
3540
dom : X Set A
3641
dom = Rel.dom ∘ toSet

docs/agda-spec/src/Ledger/BaseTypes.lagda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
\section{Base types}
1+
\section{Base Types}
22
\begin{code}[hide]
33
{-# OPTIONS --safe #-}
44

docs/agda-spec/src/Ledger/Crypto.lagda

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ record isHashableSet (T : Type) : Set₁ where
4444
constructor mkIsHashableSet
4545
field THash : Type
4646
⦃ DecEq-THash ⦄ : DecEq THash
47+
⦃ Show-THash ⦄ : Show THash
4748
⦃ DecEq-T ⦄ : DecEq T
4849
⦃ T-Hashable ⦄ : Hashable T THash
4950
open isHashableSet

docs/agda-spec/src/Ledger/PParams.lagda

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
\section{Protocol parameters}
1+
\section{Protocol Parameters}
22
\label{sec:protocol-parameters}
33
This section defines the adjustable protocol parameters of the Cardano ledger.
44
These parameters are used in block validation and can affect various features of the system,
@@ -12,6 +12,7 @@ open import Data.Rational using (ℚ)
1212
open import Relation.Nullary.Decidable
1313

1414
open import Tactic.Derive.DecEq
15+
open import Tactic.Derive.Show
1516

1617
open import Ledger.Prelude
1718
open import Ledger.Crypto
@@ -33,12 +34,13 @@ The \AgdaRecord{Acnt} record has two fields, \AgdaField{treasury} and \AgdaField
3334
the \AgdaBound{acnt} field in \AgdaRecord{NewEpochState} keeps track of the total assets that
3435
remain in treasury and reserves.
3536

36-
\begin{figure*}[h!]
37+
\begin{figure*}[ht]
3738
\begin{AgdaMultiCode}
3839
\begin{code}
3940
record Acnt : Type where
4041
\end{code}
4142
\begin{code}[hide]
43+
constructor ⟦_,_⟧ᵃ
4244
field
4345
\end{code}
4446
\begin{code}
@@ -47,6 +49,10 @@ record Acnt : Type where
4749
ProtVer : Type
4850
ProtVer = ℕ × ℕ
4951

52+
instance
53+
Show-ProtVer : Show ProtVer
54+
Show-ProtVer = Show-×
55+
5056
data pvCanFollow : ProtVer → ProtVer → Type where
5157
canFollowMajor : pvCanFollow (m , n) (m + 1 , 0)
5258
canFollowMinor : pvCanFollow (m , n) (m , n + 1)
@@ -57,11 +63,15 @@ data pvCanFollow : ProtVer → ProtVer → Type where
5763
\end{figure*}
5864
\end{NoConway}
5965

60-
\begin{figure*}[h!]
66+
\begin{figure*}[ht]
6167
\begin{AgdaMultiCode}
6268
\begin{code}
6369
data PParamGroup : Type where
64-
NetworkGroup EconomicGroup TechnicalGroup GovernanceGroup SecurityGroup : PParamGroup
70+
NetworkGroup : PParamGroup
71+
EconomicGroup : PParamGroup
72+
TechnicalGroup : PParamGroup
73+
GovernanceGroup : PParamGroup
74+
SecurityGroup : PParamGroup
6575

6676
record DrepThresholds : Type where
6777
\end{code}
@@ -86,53 +96,74 @@ record PParams : Type where
8696
\end{code}
8797
\emph{Network group}
8898
\begin{code}
89-
maxBlockSize maxTxSize : ℕ
90-
maxHeaderSize maxValSize : ℕ
99+
maxBlockSize : ℕ
100+
maxTxSize : ℕ
101+
maxHeaderSize : ℕ
102+
maxTxExUnits : ExUnits
103+
maxBlockExUnits : ExUnits
104+
maxValSize : ℕ
91105
maxCollateralInputs : ℕ
92-
maxTxExUnits maxBlockExUnits : ExUnits
93106
\end{code}
94107
\begin{code}[hide]
95108
pv : ProtVer -- retired, keep for now
96109
\end{code}
97110
\emph{Economic group}
98111
\begin{code}
99-
a b : ℕ
112+
a : ℕ
113+
b : ℕ
100114
keyDeposit : Coin
101115
poolDeposit : Coin
102116
coinsPerUTxOByte : Coin
103-
minFeeRefScriptCoinsPerByte : ℚ
104117
prices : Prices
118+
minFeeRefScriptCoinsPerByte : ℚ
105119
\end{code}
106120
\begin{code}[hide]
107121
minUTxOValue : Coin -- retired, keep for now
108122
\end{code}
109123
\emph{Technical group}
110124
\begin{code}
111-
a0 : ℚ
112125
Emax : Epoch
113126
nopt : ℕ
127+
a0 : ℚ
114128
collateralPercentage : ℕ
129+
\end{code}
130+
\begin{code}[hide]
115131
-- costmdls : Language →/⇀ CostModel (Does not work with DecEq)
132+
\end{code}
133+
\begin{code}
116134
costmdls : CostModel
117135
\end{code}
118136
\emph{Governance group}
119137
\begin{code}
120-
drepThresholds : DrepThresholds
121138
poolThresholds : PoolThresholds
139+
drepThresholds : DrepThresholds
140+
ccMinSize : ℕ
141+
ccMaxTermLength : ℕ
122142
govActionLifetime : ℕ
123-
govActionDeposit drepDeposit : Coin
143+
govActionDeposit : Coin
144+
drepDeposit : Coin
124145
drepActivity : Epoch
125-
ccMinSize ccMaxTermLength : ℕ
126-
146+
\end{code}
147+
\end{AgdaMultiCode}
148+
\caption{Protocol parameter definitions}
149+
\label{fig:protocol-parameter-declarations}
150+
\end{figure*}
151+
\begin{figure*}
152+
\begin{code}
127153
paramsWellFormed : PParams → Type
128154
paramsWellFormed pp =
129155
0 ∉ fromList ( maxBlockSize ∷ maxTxSize ∷ maxHeaderSize ∷ maxValSize
130156
∷ minUTxOValue ∷ poolDeposit ∷ collateralPercentage ∷ ccMaxTermLength
131157
∷ govActionLifetime ∷ govActionDeposit ∷ drepDeposit ∷ [] )
132158
where open PParams pp
133159
\end{code}
160+
\caption{Protocol parameter well-formedness}
161+
\label{fig:protocol-parameter-well-formedness}
162+
\end{figure*}
134163
\begin{code}[hide]
135164
instance
165+
Show-ℚ = Show _ ∋ record {M}
166+
where import Data.Rational.Show as M
136167
unquoteDecl DecEq-DrepThresholds = derive-DecEq
137168
((quote DrepThresholds , DecEq-DrepThresholds) ∷ [])
138169
unquoteDecl DecEq-PoolThresholds = derive-DecEq
@@ -141,6 +172,12 @@ instance
141172
((quote PParams , DecEq-PParams) ∷ [])
142173
unquoteDecl DecEq-PParamGroup = derive-DecEq
143174
((quote PParamGroup , DecEq-PParamGroup) ∷ [])
175+
unquoteDecl Show-DrepThresholds = derive-Show
176+
((quote DrepThresholds , Show-DrepThresholds) ∷ [])
177+
unquoteDecl Show-PoolThresholds = derive-Show
178+
((quote PoolThresholds , Show-PoolThresholds) ∷ [])
179+
unquoteDecl Show-PParams = derive-Show
180+
((quote PParams , Show-PParams) ∷ [])
144181

145182
module PParamsUpdate where
146183
record PParamsUpdate : Type where
@@ -296,10 +333,6 @@ module PParamsUpdate where
296333
((quote PParamsUpdate , DecEq-PParamsUpdate) ∷ [])
297334

298335
\end{code}
299-
\end{AgdaMultiCode}
300-
\caption{Protocol parameter declarations}
301-
\label{fig:protocol-parameter-declarations}
302-
\end{figure*}
303336
% Retiring ProtVer's documentation since ProtVer is retired.
304337
% \ProtVer represents the protocol version used in the Cardano ledger.
305338
% It is a pair of natural numbers, representing the major and minor version,
@@ -365,7 +398,7 @@ can be applied and it has a set of groups associated with it. An
365398
update is well formed if it has at least one group (i.e. if it updates
366399
something) and if it preserves well-formedness.
367400

368-
\begin{figure*}[h!]
401+
\begin{figure*}[ht]
369402
\begin{AgdaMultiCode}
370403
\begin{code}[hide]
371404
record PParamsDiff : Type₁ where

docs/agda-spec/src/Ledger/Script.lagda

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,19 @@ record P1ScriptStructure : Type₁ where
3232
record PlutusStructure : Type₁ where
3333
field Dataʰ : HashableSet
3434
Language PlutusScript CostModel Prices LangDepView ExUnits : Type
35+
PlutusV1 PlutusV2 PlutusV3 : Language
3536
⦃ ExUnit-CommutativeMonoid ⦄ : IsCommutativeMonoid' 0ℓ 0ℓ ExUnits
3637
⦃ Hashable-PlutusScript ⦄ : Hashable PlutusScript ScriptHash
38+
⦃ DecEq-Language ⦄ : DecEq Language
3739
⦃ DecEq-CostModel ⦄ : DecEq CostModel
3840
⦃ DecEq-LangDepView ⦄ : DecEq LangDepView
41+
⦃ Show-CostModel ⦄ : Show CostModel
3942

4043
field _≥ᵉ_ : ExUnits → ExUnits → Type
4144
⦃ DecEq-ExUnits ⦄ : DecEq ExUnits
4245
⦃ DecEQ-Prices ⦄ : DecEq Prices
43-
-- GetPair : ExUnits → Type × Type
44-
-- coinIsMonoidMorphism : GetPair Is ExUnit-CommutativeMonoid
45-
-- -CommutativeMonoid⟶ +-0-commutativeMonoid
46+
⦃ Show-ExUnits ⦄ : Show ExUnits
47+
⦃ Show-Prices ⦄ : Show Prices
4648

4749
open HashableSet Dataʰ renaming (T to Data; THash to DataHash) public
4850

docs/agda-spec/src/Ledger/Set/Theory.agda

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,13 @@ opaque
5454
DecEq-ℙ : ⦃ _ : DecEq A ⦄ DecEq (ℙ A)
5555
DecEq-ℙ = L.Decˡ.DecEq-Set
5656

57-
open import Axiom.Set.Rel th public
58-
hiding (_∣'_; _∣^'_; dom; range)
57+
Show-ℙ : ⦃ _ : Show A ⦄ Show (ℙ A)
58+
Show-ℙ .show = λ x Show-finite .show (x , (finiteness x))
59+
60+
import Axiom.Set.Rel
61+
module Rel = Axiom.Set.Rel th
62+
63+
open Rel public hiding (_∣'_; _∣^'_; dom; range)
5964

6065
open import Axiom.Set.Map th public
6166
renaming ( Map to infixr 1 _⇀_
@@ -76,7 +81,7 @@ module _ ⦃ _ : DecEq A ⦄ where
7681
renaming (_∣_ to _∣ʳ_; _∣_ᶜ to _∣ʳ_ᶜ)
7782

7883
open Corestriction {A} ∈-sp public
79-
hiding (_∣^_; _∣^_ᶜ) public
84+
renaming (_∣^_ to _∣^ʳ_; _∣^_ᶜ to _∣^ʳ_ᶜ) public
8085

8186
open Restrictionᵐ {A} ∈-sp public
8287
open Corestrictionᵐ {A} ∈-sp public
@@ -132,3 +137,7 @@ opaque
132137

133138
singleton-≢-∅ : {a} {x : a} ⦃ DecEq a ⦄ singleton x ≢ ∅
134139
singleton-≢-∅ {x = x} ()
140+
141+
aggregateBy : ⦃ DecEq A ⦄ ⦃ DecEq B ⦄ ⦃ DecEq C ⦄ ⦃ IsCommutativeMonoid' 0ℓ 0ℓ C ⦄
142+
Rel A B A ⇀ C B ⇀ C
143+
aggregateBy R m = mapFromFun (λ b ∑[ x m ∣ Rel.dom (R ∣^ʳ ❴ b ❵) ] x) (Rel.range R)

0 commit comments

Comments
 (0)