Skip to content

Commit 08a09e5

Browse files
committed
feat(dijkstra): discharge coin-of-{consumed,produced}Batch in UTXO PoV
Replace the two `coin-of-consumedBatch` / `coin-of-producedBatch` module parameters of `Utxo/Properties/PoV` with direct proofs. The proofs are organised as three layers: + Layer 1 — single-transaction coin equations `coin-producedTx : coin (producedTx t) ≡ cbalance (outs t) + DonationsOf t + getCoin (DirectDepositsOf t)` `coin-consumedTx : coin (MintedValueOf t) ≡ 0 → coin (consumedTx t utxo₀) ≡ cbalance (utxo₀ ∣ SpendInputsOf t) + getCoin (WithdrawalsOf t)` Each is a direct unfolding: repeated `∙-homo-Coin` to distribute `coin` across `+`, followed by `coin∘inject≗id` to strip each `inject`. The consumed version additionally uses `coin (MintedValueOf t) ≡ 0` to cancel the mint term (from UTXO premise p₆ / SUBUTXO premise). + Layer 2 — sum-over-sub-transactions coin equations `coin-∑-producedTx-sub` : pushes `coin` through the `∑ˡ`-indexed sum over `SubTransactionsOf tx` using the new `coin-∑ˡ` lemma (from `Utxo/Properties/Base`), then applies Layer 1 pointwise by list induction. `coin-∑-consumedTx-sub` : same shape, threading a `noMintingSubTxs tx` hypothesis (`∀ stx → stx ∈ˡ SubTransactionsOf tx → coin (MintedValueOf stx) ≡ 0`) through the induction so each element's Layer-1 application has its `noMint` premise available. + Layer 3 — the two batch-level coin equations `coin-of-consumedBatch` and `coin-of-producedBatch`: unfold the outer `+ inject _` / `+ ∑ˡ _` structure of `consumedBatch` / `producedBatch` by repeated `∙-homo-Coin` and `coin∘inject≗id`, substitute the Layer-1 top-level equation for the top-level summand, and substitute the Layer-2 equation for the sub-transaction sum. The produced-side proof ends with a small associative-commutative shuffle (`reshape-top`) that reorders the top-level fields from `(outs + Donations + DirectDeposits) + TxFees` to the stated `outs + TxFees + Donations + DirectDeposits`. The shuffle uses the same `swap-right` helper already used in `UTXO-V-mechanical`. + Supporting change Adds a small helper alias `noMintingSubTxs` at the top of the file to keep the sub-level mint-conservation hypothesis readable in the theorem statements. All proofs typecheck under `--safe`. The `UTXO-pov` placeholder remains; this commit delivers the coin-balance infrastructure that the eventual full proof (and the LEDGER-pov's `BatchUtxoAccounting` consumer) will depend on.
1 parent 9ee6ea0 commit 08a09e5

5 files changed

Lines changed: 384 additions & 146 deletions

File tree

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

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ record HasDepositsChange {a} (A : Type a) : Type a where
144144
field DepositsChangeOf : A → DepositsChange
145145
open HasDepositsChange ⦃...⦄ public
146146
147+
record HasDepositsChangeTop {a} (A : Type a) : Type a where
148+
field DepositsChangeTopOf : A → ℤ
149+
open HasDepositsChangeTop ⦃...⦄ public
150+
151+
record HasDepositsChangeSub {a} (A : Type a) : Type a where
152+
field DepositsChangeSubOf : A → ℤ
153+
open HasDepositsChangeSub ⦃...⦄ public
154+
147155
record HasScriptPool {a} (A : Type a) : Type a where
148156
field ScriptPoolOf : A → ℙ Script
149157
open HasScriptPool ⦃...⦄ public
@@ -218,6 +226,12 @@ instance
218226
HasDonations-UTxOState : HasDonations UTxOState
219227
HasDonations-UTxOState .DonationsOf = UTxOState.donations
220228
229+
HasDepositsChangeTop-DepositsChange : HasDepositsChangeTop DepositsChange
230+
HasDepositsChangeTop-DepositsChange .DepositsChangeTopOf = DepositsChange.depositsChangeTop
231+
232+
HasDepositsChangeSub-DepositsChange : HasDepositsChangeSub DepositsChange
233+
HasDepositsChangeSub-DepositsChange .DepositsChangeSubOf = DepositsChange.depositsChangeSub
234+
221235
unquoteDecl HasCast-DepositsChange
222236
HasCast-UTxOEnv
223237
HasCast-SubUTxOEnv
@@ -312,6 +326,16 @@ collateralCheck pp txTop utxo =
312326
× coin (balance (utxo ∣ CollateralInputsOf txTop)) * 100 ≥ (TxFeesOf txTop) * pp .collateralPercentage
313327
× (CollateralInputsOf txTop) ≢ ∅
314328
329+
producedTx : Tx ℓ → Value
330+
producedTx tx = balance (outs tx)
331+
+ inject (DonationsOf tx)
332+
+ inject (getCoin (DirectDepositsOf tx))
333+
334+
consumedTx : Tx ℓ → UTxO → Value
335+
consumedTx tx utxo = balance (utxo ∣ SpendInputsOf tx)
336+
+ MintedValueOf tx
337+
+ inject (getCoin (WithdrawalsOf tx))
338+
315339
module _ (depositsChange : DepositsChange) where
316340
317341
open DepositsChange depositsChange
@@ -328,11 +352,6 @@ module _ (depositsChange : DepositsChange) where
328352
depositRefundsTop : Coin
329353
depositRefundsTop = negPart depositsChangeTop
330354
331-
consumedTx : Tx ℓ → UTxO → Value
332-
consumedTx tx utxo = balance (utxo ∣ SpendInputsOf tx)
333-
+ MintedValueOf tx
334-
+ inject (getCoin (WithdrawalsOf tx))
335-
336355
consumed : TopLevelTx → UTxO → Value
337356
consumed txTop utxo = consumedTx txTop utxo
338357
+ inject depositRefundsTop
@@ -341,11 +360,6 @@ module _ (depositsChange : DepositsChange) where
341360
consumedBatch txTop utxo = consumed txTop utxo
342361
+ ∑ˡ[ stx ← SubTransactionsOf txTop ] (consumedTx stx utxo)
343362
+ inject depositRefundsSub
344-
producedTx : Tx ℓ → Value
345-
producedTx tx = balance (outs tx)
346-
+ inject (DonationsOf tx)
347-
+ inject (getCoin (DirectDepositsOf tx))
348-
349363
produced : TopLevelTx → Value
350364
produced txTop = producedTx txTop
351365
+ inject (TxFeesOf txTop)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ module Ledger.Dijkstra.Specification.Utxo.Properties where
1414

1515
```agda
1616
open import Ledger.Dijkstra.Specification.Utxo.Properties.Computational
17+
open import Ledger.Dijkstra.Specification.Utxo.Properties.Base
18+
open import Ledger.Dijkstra.Specification.Utxo.Properties.PoV
1719
```

src/Ledger/Dijkstra/Specification/Utxo/Properties/Base.lagda.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ private variable
5858
∙-homo-Coin = IsMagmaHomomorphism.homo (isMagmaHomomorphism coinIsMonoidHomomorphism)
5959
```
6060

61+
## `coin-∑ˡ`
62+
63+
`coin`{.AgdaField} is a monoid homomorphism from `Value`{.AgdaField} (under `+ᵛ`/`ε`) to
64+
``{.AgdaDatatype} (under `+`/`0`), so it distributes over a list-indexed sum. This
65+
is the "coin version" of the generic fact that a monoid homomorphism commutes with
66+
`foldr _∙_ ε`.
67+
68+
```agda
69+
coin-∑ˡ : ∀ {A : Type} (f : A → Value) (xs : List A)
70+
→ coin (∑ˡ[ x ← xs ] f x) ≡ sum (map (coin ∘ f) xs)
71+
coin-∑ˡ f [] = ε-homo coinIsMonoidHomomorphism
72+
coin-∑ˡ f (x ∷ xs) = trans (∙-homo-Coin (f x) (∑ˡ[ z ← xs ] f z))
73+
(cong (coin (f x) +_) (coin-∑ˡ f xs))
74+
```
75+
76+
6177
## Freshness ⇒ disjointness
6278

6379
```agda

0 commit comments

Comments
 (0)