-
Notifications
You must be signed in to change notification settings - Fork 19
[Dijkstra] CIP-159-08 phantom asset attack prevention (#1120) #1162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1117-cip-159-05-update-utxo-for-dir-deps-bal-intervals
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -83,6 +83,7 @@ record UTxOEnv : Type where | |||||||||||||||||||||||
| depositsChange : DepositsChange | ||||||||||||||||||||||||
| allScripts : ℙ Script | ||||||||||||||||||||||||
| allData : DataHash ⇀ Datum | ||||||||||||||||||||||||
| accountBalances : Rewards | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| record SubUTxOEnv : Type where | ||||||||||||||||||||||||
| field | ||||||||||||||||||||||||
|
|
@@ -93,6 +94,7 @@ record SubUTxOEnv : Type where | |||||||||||||||||||||||
| isTopLevelValid : Bool | ||||||||||||||||||||||||
| allScripts : ℙ Script | ||||||||||||||||||||||||
| allData : DataHash ⇀ Datum | ||||||||||||||||||||||||
| accountBalances : Rewards | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| The `UTxOEnv`{.AgdaRecord} carries | ||||||||||||||||||||||||
|
|
@@ -150,6 +152,10 @@ record HasDataPool {a} (A : Type a) : Type a where | |||||||||||||||||||||||
| field DataPoolOf : A → DataHash ⇀ Datum | ||||||||||||||||||||||||
| open HasDataPool ⦃...⦄ public | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| record HasAccountBalances {a} (A : Type a) : Type a where | ||||||||||||||||||||||||
| field AccountBalancesOf : A → Rewards | ||||||||||||||||||||||||
| open HasAccountBalances ⦃...⦄ public | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| record HasSlot {a} (A : Type a) : Type a where | ||||||||||||||||||||||||
| field SlotOf : A → Slot | ||||||||||||||||||||||||
| open HasSlot ⦃...⦄ public | ||||||||||||||||||||||||
|
|
@@ -176,6 +182,9 @@ instance | |||||||||||||||||||||||
| HasDataPool-UTxOEnv : HasDataPool UTxOEnv | ||||||||||||||||||||||||
| HasDataPool-UTxOEnv .DataPoolOf = UTxOEnv.allData | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| HasAccountBalances-UTxOEnv : HasAccountBalances UTxOEnv | ||||||||||||||||||||||||
| HasAccountBalances-UTxOEnv .AccountBalancesOf = UTxOEnv.accountBalances | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| HasSlot-SubUTxOEnv : HasSlot SubUTxOEnv | ||||||||||||||||||||||||
| HasSlot-SubUTxOEnv .SlotOf = SubUTxOEnv.slot | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -197,6 +206,9 @@ instance | |||||||||||||||||||||||
| HasDataPool-SubUTxOEnv : HasDataPool SubUTxOEnv | ||||||||||||||||||||||||
| HasDataPool-SubUTxOEnv .DataPoolOf = SubUTxOEnv.allData | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| HasAccountBalances-SubUTxOEnv : HasAccountBalances SubUTxOEnv | ||||||||||||||||||||||||
| HasAccountBalances-SubUTxOEnv .AccountBalancesOf = SubUTxOEnv.accountBalances | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| HasUTxO-UTxOState : HasUTxO UTxOState | ||||||||||||||||||||||||
| HasUTxO-UTxOState .UTxOOf = UTxOState.utxo | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -296,9 +308,7 @@ collateralCheck pp txTop utxo = | |||||||||||||||||||||||
| × isAdaOnly (balance (utxo ∣ CollateralInputsOf txTop)) | ||||||||||||||||||||||||
| × coin (balance (utxo ∣ CollateralInputsOf txTop)) * 100 ≥ (TxFeesOf txTop) * pp .collateralPercentage | ||||||||||||||||||||||||
| × (CollateralInputsOf txTop) ≢ ∅ | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ```agda | ||||||||||||||||||||||||
| module _ (depositsChange : DepositsChange) where | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| open DepositsChange depositsChange | ||||||||||||||||||||||||
|
|
@@ -328,9 +338,10 @@ module _ (depositsChange : DepositsChange) where | |||||||||||||||||||||||
| consumedBatch txTop utxo = consumed txTop utxo | ||||||||||||||||||||||||
| + ∑ˡ[ stx ← SubTransactionsOf txTop ] (consumedTx stx utxo) | ||||||||||||||||||||||||
| + inject depositRefundsSub | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| producedTx : Tx ℓ → Value | ||||||||||||||||||||||||
| producedTx tx = balance (outs tx) + inject (DonationsOf tx) | ||||||||||||||||||||||||
| producedTx tx = balance (outs tx) | ||||||||||||||||||||||||
| + inject (DonationsOf tx) | ||||||||||||||||||||||||
| + inject (getCoin (DirectDepositsOf tx)) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| produced : TopLevelTx → Value | ||||||||||||||||||||||||
| produced txTop = producedTx txTop | ||||||||||||||||||||||||
|
|
@@ -343,6 +354,42 @@ module _ (depositsChange : DepositsChange) where | |||||||||||||||||||||||
| + inject newDepositsSub | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ## CIP-159 Notes | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ### Preservation of Value | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| CIP-159 introduces two new fields to transactions: `directDeposits` and | ||||||||||||||||||||||||
| `balanceIntervals`. Direct deposits represent value that flows from the transaction | ||||||||||||||||||||||||
| into account addresses. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| In the preservation-of-value equation, direct deposits appear on the | ||||||||||||||||||||||||
| *produced* side: value leaves the UTxO and enters account balances. The | ||||||||||||||||||||||||
|
Comment on lines
+363
to
+366
|
||||||||||||||||||||||||
| into account addresses. | |
| In the preservation-of-value equation, direct deposits appear on the | |
| *produced* side: value leaves the UTxO and enters account balances. The | |
| into reward accounts (stake credentials). | |
| In the preservation-of-value equation, direct deposits appear on the | |
| *produced* side: value leaves the UTxO and enters reward-account balances. The |
Copilot
AI
Apr 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expression maybe id 0 (lookupᵐ? ...) encodes an important defaulting policy (missing key ⇒ 0) but is fairly opaque and likely to be repeated (it already appears elsewhere in UTXO for balance-interval checks). Consider introducing a small helper (e.g., lookupᵐ?-default0 / lookup0) to centralize the semantics and improve readability, and then use it here.
| NoPhantomWithdrawals : Rewards → TopLevelTx → Type | |
| NoPhantomWithdrawals preBalances txTop = | |
| ∀[ (addr , amt) ∈ allWithdrawals txTop ˢ ] | |
| amt ≤ maybe id 0 (lookupᵐ? preBalances (RewardAddress.stake addr)) | |
| lookup0 : Rewards → StakeCredential → Coin | |
| lookup0 balances cred = maybe id 0 (lookupᵐ? balances cred) | |
| NoPhantomWithdrawals : Rewards → TopLevelTx → Type | |
| NoPhantomWithdrawals preBalances txTop = | |
| ∀[ (addr , amt) ∈ allWithdrawals txTop ˢ ] | |
| amt ≤ lookup0 preBalances (RewardAddress.stake addr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see how this is a problem from the POV of Plutus scripts. Already in nested transactions V4 scripts cannot assume transactions to be balanced since a sub-transaction might look like it pulls ADA out of thin air. I don't understand why in that case is not an issue but with direct deposits and withdrawals it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of explaining this here, let's address this in a more prominent place where we cover not spending outputs created within the batch. And add examples. Make an issue for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what "value that flows from the transaction into account addresses" means