Skip to content

Commit c6163a3

Browse files
committed
feat(dijkstra): add UTXO and UTXOW preservation-of-value modules
Introduce three new modules implementing the UTXO-level building blocks of the Dijkstra-era preservation-of-value proof (towards closing #1123 / CIP-159-11): + `Utxo/Properties/Base.lagda.md` Era-independent helper lemmas: `∙-homo-Coin`, `newTxid⇒disj`, `outs-disjoint`. Intentionally minimal for now — the Conway Base proofs of `balance-cong`, `balance-∪`, and `split-balance` do not port verbatim because Dijkstra defines `balance` as `∑ˢ` over a set of Values rather than as `indexedSumᵐ` over a map of hashed TxOuts. Tracking issue filed for the proper port. + `Utxo/Properties/PoV.lagda.md` The Dijkstra UTXO preservation-of-value proof is split into two orthogonal pieces: - Mechanical state change (`UTXO-I-getCoin`, `UTXO-V-mechanical`): relates `getCoin s₀` to `getCoin s₁` from the UTxOState transition alone, using `split-balance` and `balance-∪`. Proved. - Batch coin balance (`batch-balance-coin`): the coin projection of the `consumedBatch ≡ producedBatch` premise (premise p₇ of the UTXO rule). Proved from the two module parameters `coin-of-consumedBatch` and `coin-of-producedBatch`, which are themselves left as assumptions for now (see PoV follow-up work). The combined `UTXO-pov` theorem is stated but left as a placeholder (`?`); its exact form depends on how `LEDGER-pov`'s `BatchUtxoAccounting` consumer threads sub-transaction state. + `Utxow/Properties/PoV.lagda.md` UTXOW-level wrappers that extract the UTXO derivation from either `UTXOW-normal` or `UTXOW-legacy` (via a shared `UTXOW⇒UTXO` extractor) and delegate to the UTXO-level lemmas. Provides `utxow-pov-invalid` in the exact shape required as a module parameter by `Ledger/Properties/PoV.lagda.md`. Proof-internal notes: + `balance-∪` and `split-balance` are currently module parameters to `Utxo/Properties/PoV` pending the port of Conway Base's balance arithmetic to Dijkstra (see tracking issue). + The 7-term +-commutative-monoid shuffle in `UTXO-V-mechanical` is proved by hand using a `swap-right` helper; this could later be replaced by a call to a commutative-monoid solver. + All three modules typecheck under `--safe`.
1 parent cf645b4 commit c6163a3

3 files changed

Lines changed: 719 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
source_branch: 1123-cip-159-11-prove-pov-and-invariants
3+
source_path: src/Ledger/Dijkstra/Specification/Utxo/Properties/Base.lagda.md
4+
---
5+
6+
# UTXO Properties: Base lemmas (Dijkstra era)
7+
8+
This module collects era-independent helper lemmas used by
9+
`Utxo.Properties.PoV`{.AgdaModule}. It currently contains:
10+
11+
+ `∙-homo-Coin`{.AgdaFunction}: the `coin` monoid-homomorphism's `_∙_` property.
12+
+ `newTxid⇒disj`{.AgdaFunction}: freshness of `TxIdOf tx` in an existing
13+
`utxo` implies `disjoint'`{.AgdaFunction} of `dom utxo`{.AgdaFunction} and
14+
`dom (outs tx)`{.AgdaFunction}.
15+
+ `outs-disjoint`{.AgdaFunction}: the specialisation used by
16+
`Utxo.Properties.PoV`{.AgdaModule}.
17+
18+
**Not yet ported from Conway**: the `balance`{.AgdaFunction}-arithmetic lemmas
19+
(`balance-cong`{.AgdaFunction}, `balance-cong-coin`{.AgdaFunction},
20+
`balance-∪`{.AgdaFunction}, `split-balance`{.AgdaFunction}). Conway's versions
21+
rely on `indexedSumᵐ-cong`{.AgdaFunction} over a finite map of hashed TxOuts;
22+
Dijkstra's `balance`{.AgdaFunction} is defined as `∑ˢ[ v ← valuesOfUTxO utxo ] v`
23+
(a sum over a `ℙ Value`{.AgdaFunction}), so the Conway proofs don't apply
24+
verbatim. Porting them requires the set-theoretic cong lemmas from
25+
`abstract-set-theory.FiniteSetTheory`{.AgdaModule}; for now, `balance-∪`{.AgdaFunction}
26+
and `split-balance`{.AgdaFunction} remain as module parameters to
27+
`Utxo.Properties.PoV`{.AgdaModule}.
28+
29+
<!--
30+
```agda
31+
{-# OPTIONS --safe #-}
32+
33+
open import Ledger.Dijkstra.Specification.Abstract using (AbstractFunctions)
34+
open import Ledger.Dijkstra.Specification.Transaction
35+
36+
module Ledger.Dijkstra.Specification.Utxo.Properties.Base
37+
(txs : _) (open TransactionStructure txs)
38+
(abs : AbstractFunctions txs) (open AbstractFunctions abs)
39+
where
40+
41+
open import Prelude; open Equivalence
42+
open import Ledger.Prelude hiding (≤-trans; ≤-antisym; All); open Properties
43+
open import Ledger.Dijkstra.Specification.Utxo txs abs
44+
45+
open import Algebra.Morphism using (module MonoidMorphisms; IsMagmaHomomorphism)
46+
47+
open MonoidMorphisms.IsMonoidHomomorphism
48+
49+
private variable
50+
ℓ : TxLevel
51+
```
52+
-->
53+
54+
## `∙-homo-Coin`
55+
56+
```agda
57+
∙-homo-Coin : ∀ (x y : Value) → coin (x + y) ≡ coin x + coin y
58+
∙-homo-Coin = IsMagmaHomomorphism.homo (isMagmaHomomorphism coinIsMonoidHomomorphism)
59+
```
60+
61+
## Freshness ⇒ disjointness
62+
63+
```agda
64+
module _ (tx : Tx ℓ) (let open Tx tx; open TxBody txBody)
65+
{utxo : UTxO} where
66+
67+
newTxid⇒disj : TxIdOf tx ∉ mapˢ proj₁ (dom utxo)
68+
→ disjoint' (dom utxo) (dom (outs tx))
69+
newTxid⇒disj id∉utxo =
70+
disjoint⇒disjoint' λ h h' → id∉utxo $ to ∈-map
71+
(-, (case from ∈-map h' of λ where
72+
(_ , refl , h'') → case from ∈-map h'' of λ where (_ , refl , _) → refl) , h)
73+
74+
-- Specialisation used by Utxo.Properties.PoV:
75+
-- freshness ⇒ (utxo ∣ SpendInputs ᶜ) and outs are disjoint.
76+
outs-disjoint : TxIdOf tx ∉ mapˢ proj₁ (dom utxo)
77+
→ disjoint (dom (utxo ∣ SpendInputsOf tx ᶜ)) (dom (outs tx))
78+
outs-disjoint fresh =
79+
λ h₁ h₂ → ∉-∅ $ proj₁ (newTxid⇒disj fresh) $ to ∈-∩ (res-comp-domᵐ h₁ , h₂)
80+
```

0 commit comments

Comments
 (0)