[Dijkstra] UTXOS and UTXO Rules#1021
Conversation
1814828 to
b6f0a59
Compare
There was a problem hiding this comment.
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
batchScriptsOkand preservation of value checking viabatchPOV - Two-branch UTXOS rule with success/failure paths based on script execution results
- Refactoring of the
Feesmodule 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.
4a690a6 to
2890db5
Compare
4e0a472 to
b796416
Compare
|
@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. |
b0da3a6 to
a60af70
Compare
e43ee89 to
4f543af
Compare
a60af70 to
e5e912f
Compare
03fc211 to
9c88f5c
Compare
e5e912f to
1f7ea3b
Compare
9c88f5c to
975c125
Compare
1f7ea3b to
4c2836d
Compare
975c125 to
c181b8e
Compare
4c2836d to
d480c57
Compare
227116d to
14efc44
Compare
bff46ee to
ca47549
Compare
7ce5bef to
ccf6e71
Compare
f92c3bb to
9674590
Compare
| ∪ txOutData tx | ||
|
|
||
| getAllScripts : TopLevelTx → UTxO → UTxO → ℙ Script | ||
| getAllScripts txTop utxo₀ utxoₙ = |
There was a problem hiding this comment.
I don't think both views are needed here (since CIP-0172) is likely to be accepted.
| (fromList (SubTransactionsOf txTop)) | ||
|
|
||
| getAllData : TopLevelTx → UTxO → UTxO → ℙ Datum | ||
| getAllData txTop utxo₀ utxoₙ = |
There was a problem hiding this comment.
Same as previous comment.
| subtransaction originally supplied it. The intent is that the ledger rules can validate | ||
| all scripts in the a without recomputing per-subtransaction script/data availability. |
There was a problem hiding this comment.
I don't understand the last phrase.
| ∙ minfee pp utxo txTop ≤ TxFeesOf txTop | ||
| ∙ consumed Γ ≡ produced | ||
| ∙ SizeOf txTop ≤ maxTxSize pp | ||
| -- ∙ refScriptsSize utxo tx ≤ pp .maxRefScriptSizePerTx -- TODO: Dijkstra analog |
There was a problem hiding this comment.
This will probably have to be checked at the top-level against those scripts coming from reference inputs outside of the batch. I added an issue about this (we can do it in a separate PR)
5b375dd to
affba86
Compare
…Txs` + 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. + Introduce subTx info type (using an alias for `TxInfo` for now). + Extend `TxInfo` with field `txInfoSubTxs : Maybe (List SubTxInfo)`. + 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) + Explain two utxo arguments + Clean up txInfoForPurpose
+ Add batch-level coin mint constraint to prevent Ada forgery (#1023) + Initial plan and improvements + Add batchMintedCoin constraint to prevent Ada forgery + Add documentation for batchMintedCoin security constraint + Use consistent aggregation syntax for batchMintedCoin Co-authored-by: williamdemeo <3528228+williamdemeo@users.noreply.github.com> --------- Co-authored-by: William DeMeo <williamdemeo@gmail.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: williamdemeo <3528228+williamdemeo@users.noreply.github.com> remove duplicate typeclass instance address PR change requests fix UTXOS and UTXO rules Update src/Ledger/Dijkstra/Specification/Utxo.lagda.md Co-authored-by: Carlos Tomé Cortiñas <carlos.tome-cortinas@iohk.io>
clean up and correct consumed/produced accounting
+ fix collectP2ScriptsWithContext
+ Fix some bugs in Dijkstra Transaction module.
+ `TxOut` is 4-tuple: `(Addr × Value × Maybe (Datum ⊎ DataHash) × Maybe Script)`
+ `UTxO.balance` uses `txOutHash`, so if that's malformed, `balance` and minfee-related code will silently go wrong or fail to typecheck.
+ The doc note "reference inputs may come from earlier outputs (prefix-applied)" is outdated; ∵ Carlos' CIP, we want an order-independent `utxoView`.
+ Fix bugs in Utxo module
+ `collectP2ScriptsWithContext` now sees batch-shared scripts (witness
inputs + ref inputs + outputs across all transactions in the batch).
+ datum-by-hash lookup (`getDatum ... (inj₂ h)`) now has an `extraData`
pool containing everything in the batch view, hashed into a map,
plus `Γ.globalData`.
+ no cyclic dependency: `Utxo` computes the batch wiring; `Script.Validation` remains generic.
+ Clean up Utxo module, removing redundancies
+ `Γ.globalScripts` is already batch-scoped via `getAllScripts tx utxo₀` (top + subs).
+ `Γ.globalData` is already batch-scoped via `getAllData tx utxo₀` (top + subs) and then hashed into a map.
+ `collectP2ScriptsWithContext` (still) unions `txDataMap tx` with `extraData` (so tx-local witness data take precedence).
+ changed globalScripts type; fixed Transaction docs + revise doc prose in Utxo module + rebase fixes + rewrite premises of UTXO rule + **No overlapping spends across subtransactions and top-level tx**: add explicit pairwise-disjointness premise for batch spending inputs. + **Reference-script/self-usable-output concern**: move reference-input validation to batch output view so reference inputs may point to outputs from full batch (including its own outputs), while keeping spending inputs mempool-safe against utxo₀.
+ Guard scripts should be collected and executed with `ScriptPurpose =
Guard...` and receive txInfoSubTxs as txInfoForPurpose intends.
+ Fix utxo (snapshot vs batch) view semantics
Previously allScripts` and `allData` could not "see" scripts/datums that
are only available via reference inputs that point into batch outputs,
because referenceOut utxo₀ tx would miss those outputs. At the same
time, we don't want to accidentally make spend-side lookups consult a
larger view than utxo₀.
To fix this, we now split the UTxO used for spend-side vs reference-side
extraction, and compute globalScripts/globalData using:
+ spend-side view = utxo₀ (mempool-safety)
+ reference-side view = utxoView = utxo₀ ∪ˡ batchOuts txTop to
resolve reference inputs to batch outputs (and to get order-agnostic
script sharing if we want it)
+ spendOut and thus spendScripts/spendData are forced to consult utxo₀.
So even if utxoₙ contains batch outputs, spend-side extraction doesn't
silently "prefer" batch outputs.
+ Reference scripts/datums that are only available on batch outputs can
now be resolved when reference inputs point to them because referenceOut sees utxoRefView.
+ improve ergonomics
+ clean up documentation
+ add more UTXO premises
Co-authored-by: Carlos Tomé Cortiñas <carlos.tome-cortinas@iohk.io>
clean up documnetation prose in Utxo module
Co-authored-by: Carlos Tomé Cortiñas <carlos.tome-cortinas@iohk.io>
Co-authored-by: Carlos Tomé Cortiñas <carlos.tome-cortinas@iohk.io>
(This is the final/cleanup commit.)
affba86 to
07e3894
Compare
Description
Plan (tentative)
This PR will close issue #1007 by
introducing batch helpers in
Ledger/Dijkstra/Specification/Utxo.lagda.md:getSubTxScripts,batchP2Inputs,batchScriptsOk)introduce level-parameterized versions of
producedandconsumedmaking
UTXOSa 2-branch relation: success vs failureWhat we want
UTXOSto decide:ok = batchScriptsOk txTopflag = 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
okSuccess branch (commit)
In the success constructor:
produced/consumed(sums acrosstxTopand all subTxs)Failure branch (collateral + nothing else)
In the failure constructor:
CollateralInputsOf txTopfeesby collateral amount (Q: how does ledger collect collateral? Does it go to fees? treasury?)Notes
I needed the 2-UTxO parameterization (
utxoSpend₀vsutxoRefView) in some places, bututxoRefViewis still just a place holder until we start tracking sub-level change of utxo state. TODO: address this once #1005 is finalized.Copilot-generated Description
This pull request introduces significant enhancements and refactoring to the Dijkstra ledger specification, focusing on fee calculation, transaction structure, script/data handling, and guard credential support. The changes improve modularity, clarify batch and mempool semantics, and generalize script/data management for the Dijkstra era.
Fee Calculation Refactoring and Generalization
src/Ledger/Dijkstra/Specification/Fees.lagda.mdmodule, mirroring the Conway fee calculation but parameterized over protocol parameters and script structures for flexibility. ThescriptsCostfunction now directly takes protocol parameters and script size, improving clarity and generality. [1] [2] [3]scriptsCostin both Conway and Dijkstra modules to match the new parameterization. [1] [2]Transaction Structure and Guard Credential Support
txSizefield and clarified the semantics oftxGuardsandtxRequiredTopLevelGuards, supporting both keys and scripts as guards for top-level and subtransactions. [1] [2] [3] [4]HasSize-Txinstance for transactions.Script and Data Handling Refactor
Scripttype. [1] [2] [3] [4]Script Validation and Guards
collectP2ScriptsWithContextand related functions to use extra data pools and unified script sets, ensuring correct precedence and context for script validation. [1] [2] [3]Documentation and Minor Improvements
These changes collectively modernize the Dijkstra ledger specification, making it more modular, extensible, and aligned with recent protocol improvements.
Checklist
CHANGELOG.md