Skip to content

Commit d192bef

Browse files
williamdemeoclaude
andcommitted
[Dijkstra] CIP-159-11c: Prove LEDGER preservation of value (#1187)
Prove `LEDGER-pov` for the Dijkstra LEDGER rule: getCoin s ≡ getCoin s', where getCoin (LedgerState) sums UTxO coin, the rewards balance, the three cert-deposit pots, and the gov-action deposits. Typechecks under --safe with no postulates or holes. Top-down plan: the supporting Certs / UTxO / Gov facts are module parameters of `Ledger.Properties.PoV`, forming the frozen contract for the follow-up PRs (#1186 utxo/utxow, #1210 certs, and a future Gov PoV). New modules: - Ledger/Properties/PoV: LEDGER-pov. The LEDGER-V case is a single LedgerState-level equational chain; direct-deposit value cancels between the UTxO and CertState sides, gov-deposit growth is matched against the produced-side govProposalsDeposits, and `bat'` converts the closed-form batch balance (#1186 shape) to the chain's two-level posPart/negPart deposit form via the batch-cert-deposits-bridge (#1210 shape) and net-arith. - Entities/Properties/PoV: ENTITIES-pov and SUBENTITIES-pov, the value-flow equations for the post-#1256 tx-signal rules. NetworkId and domain facts come from the rules' own premises; the no-truncation bound (withdrawal amount ≤ input-state balance) is an explicit hypothesis — the phantom-withdrawal gap flagged in the #1256 review, provided at the LEDGER level by the ENTITIES/SUBENTITIES-wdrls-bounded parameters. - Entities/Properties/ApplyToRewardsPoV: applyWithdrawals-pov and applyDirectDeposits-pov fold lemmas. Spec changes: - Ledger: getCoin (LedgerState) gains a coinFromGovDeposit summand (gov-action deposits live in GovActionState.deposit, not GState.deposits, yet the UTXO batch balance charges govProposalsDeposits on the produced side). - Certs: getCoin (CertState) is now total (rewards + deposit pots), with coinFromRewards / coinFromDeposits projections. - Prelude: era-independent sum lemmas (+-interleave, sum-map-+). Squash of the pre-rebase branch (13 WIP commits, head f677e1b), rebased onto master and adapted to #1250 (explicit cert deposits, closed-form newCertDeposits/refundCertDeposits), #1253/#1256 (EntitiesEnv, SUBENTITIES, tx-signal ENTITIES), #1262 (legacyMode threading), and #1263/#1265 (UTXOW premise changes). Master absorbed this branch's deposit sign-swap fix in #1250, so it is no longer part of the diff. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 665fb89 commit d192bef

9 files changed

Lines changed: 1793 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44

55
### WIP
66

7+
- Prove preservation of value for the `LEDGER` rule (`LEDGER-pov`, #1187), in new module
8+
`Ledger.Properties.PoV`. Supporting modules: `Entities.Properties.PoV`
9+
(`ENTITIES-pov`, `SUBENTITIES-pov`) and `Entities.Properties.ApplyToRewardsPoV`
10+
(`applyWithdrawals-pov`, `applyDirectDeposits-pov`). The supporting UTxO, Certs, and
11+
Gov facts are module parameters, to be discharged by #1186, #1210, and a future
12+
`Gov.Properties.PoV`.
13+
- Count governance-action deposits in `getCoin LedgerState` via a new
14+
`coinFromGovDeposit : GovState → Coin` (sum of `GovActionState.deposit`). These
15+
deposits live in `GovActionState.deposit`, not `GState.deposits`, so the three
16+
`CertState` deposit pots alone do not account for them.
17+
- Make `getCoin` on `CertState` total (rewards balance plus the three deposit pots) and
18+
add the `coinFromRewards`/`coinFromDeposits` projections in `Certs`.
719
- Move cert-deposit helpers from `Utxo` to `Certs`.
820
- Fix `updateCertDeposits`: use `foldl` (CERTS is head-first).
921
- Add `HasCoin-UTxOState` and `HasCoin-LedgerState` instances; the latter sums UTxO total, rewards balance, and all three deposit fields.

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,27 @@ module _ (pp : PParams) where
362362
addRefundCertDeposit acc _ = acc
363363
```
364364

365+
The two coin-bearing components of a `CertState`{.AgdaRecord} are the rewards
366+
(account) balances and the three deposit pots. `coinFromRewards`{.AgdaFunction} and
367+
`coinFromDeposits`{.AgdaFunction} project their totals; `getCoin`{.AgdaFunction} on a
368+
`CertState`{.AgdaRecord} is their sum, so preservation-of-value statements can be
369+
phrased at the `CertState`{.AgdaRecord} level.
370+
371+
```agda
372+
coinFromRewards : CertState → Coin
373+
coinFromRewards = rewardsBalance ∘ DStateOf
374+
375+
coinFromDeposits : CertState → Coin
376+
coinFromDeposits cs =
377+
getCoin (DepositsOf (DStateOf cs)) + getCoin (DepositsOf (PStateOf cs)) + getCoin (DepositsOf (GStateOf cs))
378+
```
379+
365380
<!--
366381
```agda
367382
instance
368383
HasCoin-CertState : HasCoin CertState
369-
HasCoin-CertState .getCoin = rewardsBalance ∘ DStateOf
384+
-- Total coin held in a CertState: the rewards balance plus the deposit pots.
385+
HasCoin-CertState .getCoin = λ cs → coinFromRewards cs + coinFromDeposits cs
370386
371387
unquoteDecl DecEq-StakePoolParams = derive-DecEq
372388
((quote StakePoolParams , DecEq-StakePoolParams) ∷ [])

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ module Ledger.Dijkstra.Specification.Entities.Properties where
1313
-->
1414

1515
```agda
16+
open import Ledger.Dijkstra.Specification.Entities.Properties.ApplyToRewardsPoV
1617
open import Ledger.Dijkstra.Specification.Entities.Properties.Computational
18+
open import Ledger.Dijkstra.Specification.Entities.Properties.PoV
1719
```

0 commit comments

Comments
 (0)