[Dijkstra] Move normal/legacy mode decision to LEDGER#1262
Open
williamdemeo wants to merge 1 commit into
Open
Conversation
williamdemeo
commented
Jul 15, 2026
| in | ||
|
|
||
| ∙ LegacyModeOf Γ ≡ false | ||
| ∙ ∀[ s ∈ p2ScriptsNeeded ] language s ∈ fromList (PlutusV4 ∷ []) -- (1) |
Member
Author
There was a problem hiding this comment.
replace with isLegacymode = false check.
williamdemeo
commented
Jul 15, 2026
| in | ||
|
|
||
| ∙ LegacyModeOf Γ ≡ true | ||
| ∙ ∃[ s ∈ p2ScriptsNeeded ] language s ∈ fromList (PlutusV1 ∷ PlutusV2 ∷ PlutusV3 ∷ []) -- (1) |
Member
Author
There was a problem hiding this comment.
replace with isLegacymode = true
carlostome
approved these changes
Jul 15, 2026
carlostome
left a comment
Collaborator
There was a problem hiding this comment.
LGTM! (modulo the comments we discussed)
Add isLegacyMode (legacy iff some needed phase-2 script is pre-V4) to Utxow and compute it once in LEDGER-V/LEDGER-I. Thread the result to UTXOW/UTXO through a new UTxOEnv.legacyMode field (UTXO's environment is plain UTxOEnv again, not UTxOEnv × Bool) and to ENTITIES via EntitiesEnv, replacing the hardcoded true. UTXOW-normal/UTXOW-legacy now select on the flag, simplifying Computational-UTXOW's dispatch. Closes #1258. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1ad4039 to
2f5b5ce
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #1258.
Previously the normal-vs-legacy decision lived in two places that could disagree:
UTXOWchose a mode nondeterministically via its two rules (feedingfalse/trueintoUTXO's self-balance premise), whileLEDGER-Vpassed a hardcodedtruetoENTITIES— making thelegacyMode ≡ falsebranch ofENTITIES(partial top-level withdrawals) unreachable and letting an all-V4 transaction get normal-mode UTxO accounting but legacy-mode withdrawal treatment.This PR makes the decision once, in
LEDGER, and threads the result through the rules' environments.Changes
Utxow: newneededP2ScriptsandisLegacyMode : UTxO → ℙ Script → TopLevelTx → Bool— legacy exactly when some needed phase-2 script uses a pre-V4 Plutus language (the same criterionComputational-UTXOWalready used to dispatch).UTXOW-normal/UTXOW-legacygain a first premiseLegacyModeOf Γ ≡ false/≡ trueand passΓtoUTXOunchanged. Their language premises remain as checks, so the environment flag is validated rather than trusted, and each rule keeps its standalone meaning.Utxo:UTxOEnvgains a namedlegacyMode : Boolfield (mirroring howisTopLevelValidis threaded viaSubUTxOEnv), with aHasLegacyMode/LegacyModeOfaccessor.UTXO's environment is plainUTxOEnvagain instead ofUTxOEnv × Bool.Ledger:LEDGER-V/LEDGER-IcomputelegacyMode = isLegacyMode utxo₀ allScripts txand thread it toUTXOW/UTXOviaUTxOEnvand toENTITIESviaEntitiesEnv, replacing the hardcodedtrue. All three rules now see one consistent flag.Computational:
Computational-UTXOWdispatches on the flag premises, which removes theDecV3decision and theV1,V2,V3∩V4⊆∅disjointness lemma;Computational-UTXOloses the product-env plumbing;Computational-LEDGERmirrors the new rule environments.Foreign/Utxo:utxo-stepis nowUTxOEnv → UTxOState → Tx TxLevelTop → …(the flag moved into the auto-derivedMkUTxOEnv; no Haskell consumers exist yet).Verification
The full
Ledger.Dijkstraaggregate typechecks (Agda 2.8.0 via the Nix flake), as doesSpecification/Computational.lagda.md, which sits outside the aggregate's import graph. No modules outsidesrc/Ledger/Dijkstraimport the changed ones.Out of scope
The legacy-mode withdrawal gap is not fixed here: the
ENTITIESlegacy branch still requires the top-level withdrawal to equal the current (post-SUBLEDGERS) balance with norewards₀bound, andUsesV4Featuresonly inspects top-level fields, so a legacy batch can still carry sub-transactions with direct deposits and drain them. This is now tracked in Issue #1261.🤖 Generated with Claude Code
Checked/revised by @williamdemeo
Checklist
CHANGELOG.md