Skip to content

[Dijkstra] CIP-159-10: Apply batch-wide direct deposits in LEDGER rule (#1122)#1161

Open
williamdemeo wants to merge 1 commit into1117-cip-159-05-update-utxo-for-dir-deps-bal-intervalsfrom
1122-cip-159-10-update-ledger-direct-deps-and-account-bals
Open

[Dijkstra] CIP-159-10: Apply batch-wide direct deposits in LEDGER rule (#1122)#1161
williamdemeo wants to merge 1 commit into1117-cip-159-05-update-utxo-for-dir-deps-bal-intervalsfrom
1122-cip-159-10-update-ledger-direct-deps-and-account-bals

Conversation

@williamdemeo
Copy link
Copy Markdown
Member

@williamdemeo williamdemeo commented Apr 12, 2026

Description

This PR closes Issue #1122.

NOTE FOR REVIEWER. This PR depends on #1160 (UTxO rules; Issue #1117) which added accountBalances threading. The heavy lifting was already done in that PR; this PR merely adds the direct deposit application step to the LEDGER rule, so the target branch is that of PR #1160 (1117-cip-159-05-update-utxo-for-dir-deps-bal-intervals).


Changes

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

  • Updated LEDGER-V output. After all sub-rule transitions, batch-wide direct deposits are applied to the final CertState:

    certStateFinal = record certState₂
      { dState = applyDirectDeposits (allDirectDeposits tx) (DStateOf certState₂) }

    The output LedgerState uses certStateFinal instead of certState₂, and rmOrphanDRepVotes receives certStateFinal so it sees the post-deposit state.

  • LEDGER-I unchanged since invalid batches (IsValidFlagOf tx ≡ false) do not apply direct deposits, consistent with existing collateral collection semantics.

  • New documentation. Explains the application ordering and the phantom asset prevention rationale.

src/Ledger/Dijkstra/Specification/Ledger/Properties/Computational.lagda.md:

  • Updated computeProof (valid branch). Computes certStateFinal and uses it in the output LedgerState. The invalid branch is unchanged.

  • completeness (valid branch) Requires no changes — both computeProof and the LEDGER-V conclusion compute the same certStateFinal term, so refl holds.


Design Notes

  • Batch-level, not per-sub-transaction. Direct deposits are applied once after all transitions, not interleaved with sub-transaction processing. CIP-159 explicitly forbids per-sub-transaction application to prevent phantom asset attacks (where a deposit from one subtransaction inflates the balance available for withdrawal by another subtransaction).

  • Applied after CERTS. Withdrawals in CERTS are checked against pre-batch balances (via accountBalances in UTxOEnv). Applying deposits after ensures withdrawals can't access freshly deposited funds within the same batch.

  • depositsChange uses certState₂, not certStateFinal. The deposit change computation reflects registration/deregistration deposit changes only — not direct deposit value transfers. This is correct because direct deposits are not gov proposal deposits.

  • rmOrphanDRepVotes uses certStateFinal. Semantically correct (it should see the final DRep state), though in practice applyDirectDeposits only modifies rewards, not voteDelegs or dreps, so the result is the same either way.

  • allDirectDeposits and applyDirectDeposits are pre-existing. allDirectDeposits (in Transaction.lagda.md) aggregates direct deposits across the batch using ∪⁺. applyDirectDeposits (in Certs.lagda.md) applies them to a DState via ∪⁺.


Acceptance criteria checklist


Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • Any semantic changes to the specifications are documented in CHANGELOG.md
  • Code is formatted according to CONTRIBUTING.md
  • Self-reviewed the diff

@williamdemeo williamdemeo self-assigned this Apr 12, 2026
@williamdemeo williamdemeo force-pushed the 1122-cip-159-10-update-ledger-direct-deps-and-account-bals branch from 6b7ea58 to 76e3fb5 Compare April 12, 2026 01:12
@williamdemeo williamdemeo marked this pull request as ready for review April 12, 2026 01:12
@williamdemeo williamdemeo requested a review from Copilot April 14, 2026 02:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Applies CIP-159 batch-wide direct deposits at the end of a valid LEDGER transition by updating the final CertState (and ensuring the computational proof produces the same final state).

Changes:

  • Update LEDGER-V to apply applyDirectDeposits (allDirectDeposits tx) to the final CertState and use that state for rmOrphanDRepVotes and the output LedgerState.
  • Update computeProof (valid branch) to construct/use the same post-deposit CertState.
  • Add documentation and a CHANGELOG entry describing ordering rationale and phantom-asset prevention.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/Ledger/Dijkstra/Specification/Ledger.lagda.md Applies batch-wide direct deposits in LEDGER-V output and documents the ordering/rationale.
src/Ledger/Dijkstra/Specification/Ledger/Properties/Computational.lagda.md Aligns computeProof output with the updated LEDGER-V post-deposit CertState.
CHANGELOG.md Notes the behavioral/spec change for CIP-159 direct deposits in LEDGER-V.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Ledger/Dijkstra/Specification/Ledger.lagda.md Outdated
Comment thread src/Ledger/Dijkstra/Specification/Ledger.lagda.md Outdated
@williamdemeo williamdemeo added the CIP 159 Account Address Enhancement label Apr 16, 2026
@williamdemeo williamdemeo force-pushed the 1117-cip-159-05-update-utxo-for-dir-deps-bal-intervals branch from 37f2bf6 to 33b565b Compare April 21, 2026 19:17
@williamdemeo williamdemeo force-pushed the 1122-cip-159-10-update-ledger-direct-deps-and-account-bals branch from 76e3fb5 to f74ea80 Compare April 21, 2026 19:19
@williamdemeo williamdemeo force-pushed the 1117-cip-159-05-update-utxo-for-dir-deps-bal-intervals branch from 33b565b to 0c5d520 Compare April 22, 2026 14:57
@williamdemeo williamdemeo force-pushed the 1122-cip-159-10-update-ledger-direct-deps-and-account-bals branch from f74ea80 to a3ea21c Compare April 22, 2026 14:59
@williamdemeo williamdemeo force-pushed the 1117-cip-159-05-update-utxo-for-dir-deps-bal-intervals branch from 0c5d520 to 389d947 Compare April 24, 2026 00:47
@williamdemeo williamdemeo force-pushed the 1122-cip-159-10-update-ledger-direct-deps-and-account-bals branch 2 times, most recently from b889649 to d08050d Compare April 24, 2026 02:52
#1122)

After all sub-rule transitions (`SUBLEDGERS`, `CERTS`, `GOVS`, `UTXOW`),
apply batch-wide direct deposits to the final CertState via
`applyDirectDeposits` and `allDirectDeposits`.

`Ledger.lagda.md`:
+  Update `LEDGER-V` output: compute `certStateFinal` by applying
   `allDirectDeposits` to `certState₂`, use `certStateFinal` in the
   output `LedgerState` and in `rmOrphanDRepVotes`;
+  `LEDGER-I` unchanged (invalid batches don't apply deposits);
+  Document direct deposit application ordering and phantom asset
   prevention rationale.

`Ledger/Properties/Computational.lagda.md`:
+  Update `computeProof` valid branch to compute `certStateFinal` and use
   it in the output `LedgerState`.
+  Clean up redundant code.
@williamdemeo williamdemeo force-pushed the 1122-cip-159-10-update-ledger-direct-deps-and-account-bals branch from d08050d to b7ce2de Compare April 24, 2026 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CIP 159 Account Address Enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Dijkstra] CIP-159-10: Update LEDGER rule to integrate direct deposits and thread account balances

2 participants