Skip to content

Commit 2bae9f8

Browse files
authored
Merge branch 'master' into 965-refactor-properties
2 parents e812fca + f6ee32d commit 2bae9f8

File tree

5 files changed

+104
-29
lines changed

5 files changed

+104
-29
lines changed

build-tools/static/hs-src/src/MAlonzo/Code/Ledger/Foreign/API.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ import MAlonzo.Code.Ledger.Conway.Foreign.HSLedger.Ledger as X
3535
import MAlonzo.Code.Ledger.Conway.Foreign.HSLedger.NewEpoch as X
3636
(NewEpochState(..), newEpochStep)
3737
import MAlonzo.Code.Ledger.Conway.Foreign.HSLedger.Ratify as X
38-
(StakeDistrs(..), RatifyEnv(..), RatifyState(..), ratifyStep)
38+
(StakeDistrs(..), RatifyEnv(..), RatifyState(..), ratifyStep
39+
,acceptedBySPO, acceptedByDRep, acceptedByCC)
3940
import MAlonzo.Code.Ledger.Conway.Foreign.HSLedger.Rewards as X
4041
(HsRewardUpdate(..), Snapshot(..), Snapshots(..))
4142
import MAlonzo.Code.Ledger.Conway.Foreign.HSLedger.Utxo as X

src/Ledger/Conway/Conformance.agda

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
This module provides the model used to do conformance testing of the Haskell
2+
implementation of the Ledger.
3+
4+
The conformance model differs from the Conway specification in how deposits are
5+
stored in the Ledger state.
6+
7+
In the Conway specification, deposits are stored in `LState.utxoSt.deposits`{.AgdaField}.
8+
The conformance model, on the other hand, separates deposits in three disjoint
9+
maps:
10+
11+
* `LState.utxoSt.deposits`{.AgdaField}
12+
* `LState.certState.dState.deposits`{.AgdaField}
13+
* `LState.certState.gState.deposits`{.AgdaField}
14+
15+
## Motivation
16+
17+
The conformance model follows the way in which the Haskell implementation stores
18+
the deposits, which makes it possible to compare the behaviors of the conformance
19+
model and the implementation of the `UTXOS`{.AgdaDatatype} rule.
20+
21+
The UTXOS rule transforms `UTxOState`s. While the specification updates the
22+
deposits in this rule, the implementation cannot do so because its input state
23+
does not contain the deposits in `DState` and `GState`.
24+
25+
Other rules which use `UTXOS`{.AgdaDatatype} are in a similar predicament,
26+
namely `UTXO`{.AgdaDatatype} and `UTXOW`{.AgdaDatatype}. The
27+
`LEDGER`{.AgdaDatatype} rule, which uses `UTXOW`{.AgdaDatatype}, is the first
28+
rule where the implementation has all the state necessary to reconstruct the
29+
full deposits that the specification needs.
30+
31+
## Guarantees
32+
33+
Since we still want to check that the implementation behaves as the
34+
specification, there is a proof of the equivalence between the conformance model
35+
and the specification:
36+
37+
* `Ledger.Conway.Conformance.Equivalence.bisimilarityProof`{.AgdaBound}
38+
39+
## Alternatives
40+
41+
Rather than providing a conformance model, we could have changed the Conway
42+
specification to match the implementation way of storing deposits. However,
43+
there are trade offs to consider. Putting the deposits together in one place
44+
makes some proofs simpler, while splitting them as in the implementation makes
45+
it more convenient to write the update functions for the separated pieces.
46+
47+
While we could decide the tradeoff for a particular implementation, it would be
48+
difficult to adjust the specification when multiple implementations need to be
49+
accommodated.
50+
51+
Yet another option could have been to skip testing specifically for the
52+
`UTXOS`{.AgdaDatatype} rule. This was a difficulty for testing, since spotting
53+
differences in a rule is harder when it is combined with other rules like the
54+
`LEDGER`{.AgdaDatatype} rule does.
55+
56+
```agda
57+
{-# OPTIONS --safe #-}
58+
module Ledger.Conway.Conformance where
59+
60+
import Ledger.Conway.Conformance.Certs
61+
import Ledger.Conway.Conformance.Certs.Properties
62+
import Ledger.Conway.Conformance.Chain
63+
import Ledger.Conway.Conformance.Chain.Properties
64+
import Ledger.Conway.Conformance.Equivalence
65+
import Ledger.Conway.Conformance.Epoch
66+
import Ledger.Conway.Conformance.Epoch.Properties
67+
import Ledger.Conway.Conformance.Gov
68+
import Ledger.Conway.Conformance.Ledger
69+
import Ledger.Conway.Conformance.Ledger.Properties
70+
import Ledger.Conway.Conformance.Properties
71+
import Ledger.Conway.Conformance.Utxo
72+
import Ledger.Conway.Conformance.Utxo.Properties
73+
import Ledger.Conway.Conformance.Utxow
74+
import Ledger.Conway.Conformance.Utxow.Properties
75+
import Ledger.Conway.Conformance.Script
76+
```

src/Ledger/Conway/Foreign/HSLedger/Ratify.agda

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import Data.Rational.Show as Rational
1414

1515
import Foreign.Haskell.Pair as F
1616
open import Ledger.Conway.Specification.Ratify it
17+
hiding (acceptedByCC; acceptedByDRep; acceptedBySPO)
18+
import Ledger.Conway.Specification.Ratify it as Ratify
1719
open import Ledger.Conway.Specification.Ratify.Properties.Computational it
1820

1921
instance
@@ -62,3 +64,18 @@ instance
6264
Show-RATIFIES : {Γ s sig s'}
6365
Show (Γ ⊢ s ⇀⦇ sig ,RATIFIES⦈ s')
6466
Show-RATIFIES {Γ} {s} {sig} .show r = "" -- ratify-debug (to Γ) (to s) (to sig)
67+
68+
-- Expose acceptedBy predicates for conformance
69+
70+
acceptedByCC : HsType (RatifyEnv EnactState GovActionState Bool)
71+
acceptedByCC = λ Γ es st to (does (acceptedByCC? (from Γ) (from es) (from st)))
72+
73+
acceptedByDRep : HsType (RatifyEnv EnactState GovActionState Bool)
74+
acceptedByDRep = λ Γ es st to (does (acceptedByDRep? (from Γ) (from es) (from st)))
75+
76+
acceptedBySPO : HsType (RatifyEnv EnactState GovActionState Bool)
77+
acceptedBySPO = λ Γ es st to (does (acceptedBySPO? (from Γ) (from es) (from st)))
78+
79+
{-# COMPILE GHC acceptedByCC as acceptedByCC #-}
80+
{-# COMPILE GHC acceptedByDRep as acceptedByDRep #-}
81+
{-# COMPILE GHC acceptedBySPO as acceptedBySPO #-}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -667,17 +667,17 @@ opaque
667667
Is-nothing? {x = x} = All.dec (const $ no id) x
668668
where import Data.Maybe.Relation.Unary.All as All
669669
670-
accepted? : ∀ Γ es st → Dec (accepted Γ es st)
671-
accepted? Γ es st = acceptedByCC? Γ es st ×-dec acceptedByDRep? Γ es st ×-dec acceptedBySPO? Γ es st
672-
where
673-
acceptedByCC? : ∀ Γ es st → Dec (acceptedByCC Γ es st)
674-
acceptedByCC? _ _ _ = _ ℚ.≤? _ ×-dec (_ ≥? _ ⊎-dec (Is-nothing? ×-dec ¿ _ ¿))
670+
acceptedByCC? : ∀ Γ es st → Dec (acceptedByCC Γ es st)
671+
acceptedByCC? _ _ _ = _ ℚ.≤? _ ×-dec (_ ≥? _ ⊎-dec (Is-nothing? ×-dec ¿ _ ¿))
672+
673+
acceptedByDRep? : ∀ Γ es st → Dec (acceptedByDRep Γ es st)
674+
acceptedByDRep? _ _ _ = _ ℚ.≤? _
675675
676-
acceptedByDRep? : ∀ Γ es st → Dec (acceptedByDRep Γ es st)
677-
acceptedByDRep? _ _ _ = _ ℚ.≤? _
676+
acceptedBySPO? : ∀ Γ es st → Dec (acceptedBySPO Γ es st)
677+
acceptedBySPO? _ _ _ = _ ℚ.≤? _
678678
679-
acceptedBySPO? : ∀ Γ es st → Dec (acceptedBySPO Γ es st)
680-
acceptedBySPO? _ _ _ = _ ℚ.≤? _
679+
accepted? : ∀ Γ es st → Dec (accepted Γ es st)
680+
accepted? Γ es st = acceptedByCC? Γ es st ×-dec acceptedByDRep? Γ es st ×-dec acceptedBySPO? Γ es st
681681
682682
expired? : ∀ e st → Dec (expired e st)
683683
expired? e st = ¿ expired e st ¿

0 commit comments

Comments
 (0)