Skip to content

Conversation

@williamdemeo
Copy link
Member

@williamdemeo williamdemeo commented Jan 8, 2026

Description

Stacked PR (This PR targets #1015.)

Plan (tentative)

This PR will close issue #1007 by

  • introducing batch helpers in Ledger/Dijkstra/Specification/Utxo.lagda.md:

    • batch collection/verification (getSubTxScripts, batchP2Inputs, batchScriptsOk)
  • introduce level-parameterized versions of produced and consumed

  • making UTXOS a 2-branch relation: success vs failure

    What we want UTXOS to decide:

    • ok = batchScriptsOk txTop
    • flag = Tx.isValid txTop (top-level only)

    Then:

    • require flag ≡ ok (so the transaction's claimed validity matches the ledger's batch execution result)

    • branch on ok

    • Success branch (commit)

      In the success constructor:

      • apply the normal batch effects (UTxO update, fees accounting, deposits/gov/etc)
      • enforce batch POV using level-parameterized produced/consumed (sums across txTop and all subTxs)
      • enforce fee rule: only top-level fee counts (already true by shape; still make it explicit in the accounting)
    • Failure branch (collateral + nothing else)

      In the failure constructor:

      • Apply only collateral collection using CollateralInputsOf txTop
      • Don't apply any other UTxO changes from the batch (no outputs, no withdrawals, no cert effects, etc.)
      • Update fees by collateral amount (Q: how does ledger collect collateral? Does it go to fees? treasury?)

Notes

I needed the 2-UTxO parameterization (utxoSpend₀ vs utxoRefView) in some places, but
utxoRefView is still just a place holder until we start tracking sub-level change of utxo state. TODO: address this once #1005 is finalized.

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 force-pushed the 1007-dijkstra-utxos-batch-level-validity branch from 1814828 to b6f0a59 Compare January 8, 2026 05:27
@williamdemeo williamdemeo self-assigned this Jan 8, 2026
@williamdemeo williamdemeo changed the title Add support for batch-level validity checking [Dijkstra] UTXOS Rule with batch-level validity checking Jan 8, 2026
@williamdemeo williamdemeo moved this to In Progress in Dijkstra formal spec Jan 8, 2026
@williamdemeo williamdemeo marked this pull request as ready for review January 8, 2026 06:51
@williamdemeo williamdemeo requested a review from Copilot January 8, 2026 06:51
Copy link
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

This PR implements batch-level validity checking for the UTXOS rule in the Dijkstra specification, addressing issues #1006 and #1007. It introduces a two-branch UTXOS relation that handles both successful script execution (applying all batch effects) and failed execution (collecting only collateral).

Key changes include:

  • Introduction of batch-level script validation with batchScriptsOk and preservation of value checking via batchPOV
  • Two-branch UTXOS rule with success/failure paths based on script execution results
  • Refactoring of the Fees module to be parameterized by protocol parameters

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/Ledger/Dijkstra/Specification/Utxo.lagda.md Implements batch-level UTXOS rule with success/failure branches, batch operations, and UTxO state transitions
src/Ledger/Dijkstra/Specification/Transaction.lagda.md Adds level-dependent and level-independent type classes for transaction components, adds txSize field to Tx
src/Ledger/Dijkstra/Specification/Script/Validation.lagda.md Updates references from ValueOf to MintedValueOf for consistency
src/Ledger/Conway/Specification/Fees.lagda.md Refactors module to take protocol parameters as module parameter; changes scriptsCost signature from PParams → ℕ → Coin to ℕ → Coin
src/Ledger/Conway/Specification/Utxo.lagda.md Updates import statement for scriptsCost (but not all call sites)
src/Ledger/Conway/Conformance/Utxo.agda Updates import statement for scriptsCost (but not all call sites)

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

Comment on lines 371 to 372
depositsSuccess = foldr (λ sub deps → updateDeposits (PParamsOf Γ) sub deps)
(updateDeposits (PParamsOf Γ) txTop (DepositsOf s))
(SubTransactionsOf txTop)
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

depositsSuccess applies updateDeposits to each sub-transaction, but the batch preservation-of-value check batchPOV only uses depositsChange for the top-level transaction (Δdeposits) and completely ignores deposit/gov-proposal effects of sub-transactions. This lets a batch include sub-transactions with deposit-creating or deposit-refunding certificates/proposals that change DepositsOf in successState without any balancing term in batchConsumed/batchProduced, so total Ada in the UTxOState can increase or decrease even when batchPOV holds. To prevent this, the deposit component of preservation-of-value must also account for sub-transaction certificates/proposals (e.g. by incorporating their depositsChange into consumedSub/producedSub or by computing a single batch-level deposits delta and using that consistently for both batchPOV and depositsSuccess).

Suggested change
depositsSuccess = foldr (λ sub deps → updateDeposits (PParamsOf Γ) sub deps)
(updateDeposits (PParamsOf Γ) txTop (DepositsOf s))
(SubTransactionsOf txTop)
depositsSuccess = updateDeposits (PParamsOf Γ) txTop (DepositsOf s)

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

subtransactions have no deposits, so they cannot introduce or refund deposits, but we might want to include an additional check/invariant for this.

@williamdemeo williamdemeo force-pushed the 1006-dijkstra-batch-aware-collectp2scriptswithcontext branch from 4a690a6 to 2890db5 Compare January 9, 2026 03:06
@williamdemeo williamdemeo force-pushed the 1007-dijkstra-utxos-batch-level-validity branch from 4e0a472 to b796416 Compare January 9, 2026 03:33
Copy link
Contributor

Copilot AI commented Jan 9, 2026

@williamdemeo I've opened a new pull request, #1023, to work on those changes. Once the pull request is ready, I'll request review from you.

@williamdemeo williamdemeo force-pushed the 1006-dijkstra-batch-aware-collectp2scriptswithcontext branch from b0da3a6 to a60af70 Compare January 9, 2026 05:52
@williamdemeo williamdemeo force-pushed the 1007-dijkstra-utxos-batch-level-validity branch from e43ee89 to 4f543af Compare January 9, 2026 05:54
@williamdemeo williamdemeo marked this pull request as draft January 9, 2026 06:20
@williamdemeo williamdemeo force-pushed the 1006-dijkstra-batch-aware-collectp2scriptswithcontext branch from a60af70 to e5e912f Compare January 9, 2026 15:01
@williamdemeo williamdemeo force-pushed the 1007-dijkstra-utxos-batch-level-validity branch from 03fc211 to 9c88f5c Compare January 9, 2026 15:03
@williamdemeo williamdemeo force-pushed the 1006-dijkstra-batch-aware-collectp2scriptswithcontext branch from e5e912f to 1f7ea3b Compare January 9, 2026 15:05
@williamdemeo williamdemeo force-pushed the 1007-dijkstra-utxos-batch-level-validity branch from 9c88f5c to 975c125 Compare January 9, 2026 15:05
@williamdemeo williamdemeo force-pushed the 1006-dijkstra-batch-aware-collectp2scriptswithcontext branch from 1f7ea3b to 4c2836d Compare January 10, 2026 00:14
@williamdemeo williamdemeo force-pushed the 1007-dijkstra-utxos-batch-level-validity branch from 975c125 to c181b8e Compare January 10, 2026 00:14
@williamdemeo williamdemeo force-pushed the 1006-dijkstra-batch-aware-collectp2scriptswithcontext branch from 4c2836d to d480c57 Compare January 12, 2026 16:31
@williamdemeo williamdemeo force-pushed the 1007-dijkstra-utxos-batch-level-validity branch from 227116d to 14efc44 Compare January 12, 2026 17:00
@williamdemeo williamdemeo force-pushed the 1006-dijkstra-batch-aware-collectp2scriptswithcontext branch from bff46ee to ca47549 Compare January 13, 2026 05:47
Base automatically changed from 1006-dijkstra-batch-aware-collectp2scriptswithcontext to master January 13, 2026 05:55
williamdemeo and others added 15 commits January 12, 2026 23:03
+  Remove contradiction between "ref inputs may refer to earlier tx outputs in the batch" vs "all inputs must exist before applying any tx in the batch." The new text punts the exact constraint to the UTxO rules (where it belongs).
+  Fix Plutus bullet (old "nor earlier versions" reads like "no Plutus at all").
+  Align fees with current Agda (`txFee : InTopLevel …`), but leave room for later CIP-driven updates.
1. Introduce subTx info type (using an alias for `TxInfo` for now).
2. Extend `TxInfo` with field `txInfoSubTxs : Maybe (List SubTxInfo)`.
3. Define a purpose-built builder:

   + Top-level Guard scripts ⇒ `txInfoSubTxs = just (...)`
   + Everything else ⇒ `txInfoSubTxs = nothing`
   + SubTx scripts ⇒ always `nothing` (even for `Guard` at sub level)
* improvements

* Initial plan

* Add batchMintedCoin constraint to prevent Ada forgery

Co-authored-by: williamdemeo <[email protected]>

* Add documentation for batchMintedCoin security constraint

Co-authored-by: williamdemeo <[email protected]>

* Use consistent aggregation syntax for batchMintedCoin

Co-authored-by: williamdemeo <[email protected]>

---------

Co-authored-by: William DeMeo <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: williamdemeo <[email protected]>
@williamdemeo williamdemeo force-pushed the 1007-dijkstra-utxos-batch-level-validity branch from 14efc44 to 36c1d92 Compare January 13, 2026 06:16
@williamdemeo williamdemeo marked this pull request as ready for review January 13, 2026 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants