|
3 | 3 | {-# OPTIONS_GHC -fno-specialize #-}
|
4 | 4 | {-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:conservative-optimisation #-}
|
5 | 5 | {-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:defer-errors #-}
|
| 6 | +{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:optimize #-} |
6 | 7 | -- Plutus core version to compile to. In babbage era, that is Cardano protocol
|
7 | 8 | -- version 7 and 8, only plutus-core version 1.0.0 is available.
|
8 | 9 | {-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:target-version=1.0.0 #-}
|
@@ -41,11 +42,10 @@ import PlutusLedgerApi.V2 (
|
41 | 42 | TxInInfo (..),
|
42 | 43 | TxInfo (..),
|
43 | 44 | TxOut (..),
|
44 |
| - TxOutRef (..), |
45 | 45 | UpperBound (..),
|
46 | 46 | Value (Value),
|
47 | 47 | )
|
48 |
| -import PlutusLedgerApi.V2.Contexts (findOwnInput, spendsOutput) |
| 48 | +import PlutusLedgerApi.V2.Contexts (findOwnInput, findTxInByTxOutRef) |
49 | 49 | import PlutusTx (CompiledCode)
|
50 | 50 | import PlutusTx qualified
|
51 | 51 | import PlutusTx.AssocMap qualified as AssocMap
|
@@ -240,34 +240,42 @@ checkIncrement ::
|
240 | 240 | IncrementRedeemer ->
|
241 | 241 | Bool
|
242 | 242 | checkIncrement ctx@ScriptContext{scriptContextTxInfo = txInfo} openBefore redeemer =
|
243 |
| - -- FIXME: spec is mentioning the n also needs to be unchanged - what is n here? |
| 243 | + -- FIXME: spec is mentioning the n also needs to be unchanged - what is n here? utxo hash? |
244 | 244 | -- "parameters cid, 𝑘̃ H , 𝑛, 𝑇 stay unchanged"
|
245 | 245 | mustNotChangeParameters (prevParties, nextParties) (prevCperiod, nextCperiod) (prevHeadId, nextHeadId)
|
246 | 246 | && mustIncreaseVersion
|
247 |
| - && checkSnapshotSignature |
248 | 247 | && mustIncreaseValue
|
249 | 248 | && mustBeSignedByParticipant ctx prevHeadId
|
| 249 | + && checkSnapshotSignature |
250 | 250 | && claimedDepositIsSpent
|
251 | 251 | where
|
252 |
| - deposited = foldMap (depositDatum . txInInfoResolved) (txInfoInputs txInfo) |
| 252 | + inputs = txInfoInputs txInfo |
| 253 | + |
| 254 | + depositInput = |
| 255 | + case findTxInByTxOutRef increment txInfo of |
| 256 | + Nothing -> traceError $(errorCode DepositInputNotFound) |
| 257 | + Just i -> i |
253 | 258 |
|
254 |
| - depositHash = hashPreSerializedCommits deposited |
| 259 | + commits = depositDatum $ txInInfoResolved depositInput |
255 | 260 |
|
256 |
| - depositInput = txInfoInputs txInfo !! 1 |
| 261 | + depositHash = hashPreSerializedCommits commits |
257 | 262 |
|
258 | 263 | depositRef = txInInfoOutRef depositInput
|
259 | 264 |
|
260 | 265 | depositValue = txOutValue $ txInInfoResolved depositInput
|
261 | 266 |
|
262 |
| - headInValue = txOutValue $ txInInfoResolved (head (txInfoInputs txInfo)) |
| 267 | + headInValue = |
| 268 | + case find (hasST prevHeadId) $ txOutValue . txInInfoResolved <$> inputs of |
| 269 | + Nothing -> traceError $(errorCode HeadInputNotFound) |
| 270 | + Just i -> i |
263 | 271 |
|
264 |
| - headOutValue = foldMap txOutValue $ txInfoOutputs txInfo |
| 272 | + headOutValue = txOutValue $ head $ txInfoOutputs txInfo |
265 | 273 |
|
266 | 274 | IncrementRedeemer{signature, snapshotNumber, increment} = redeemer
|
267 | 275 |
|
268 | 276 | claimedDepositIsSpent =
|
269 | 277 | traceIfFalse $(errorCode DepositNotSpent) $
|
270 |
| - depositRef == increment && spendsOutput txInfo (txOutRefId depositRef) (txOutRefIdx depositRef) |
| 278 | + depositRef == increment |
271 | 279 |
|
272 | 280 | checkSnapshotSignature =
|
273 | 281 | verifySnapshotSignature nextParties (nextHeadId, prevVersion, snapshotNumber, nextUtxoHash, depositHash, emptyHash) signature
|
@@ -623,6 +631,7 @@ makeContestationDeadline cperiod ScriptContext{scriptContextTxInfo} =
|
623 | 631 | _ -> traceError $(errorCode CloseNoUpperBoundDefined)
|
624 | 632 | {-# INLINEABLE makeContestationDeadline #-}
|
625 | 633 |
|
| 634 | +-- | This is safe only because usually Head transaction only consume one input. |
626 | 635 | getHeadInput :: ScriptContext -> TxInInfo
|
627 | 636 | getHeadInput ctx = case findOwnInput ctx of
|
628 | 637 | Nothing -> traceError $(errorCode ScriptNotSpendingAHeadInput)
|
|
0 commit comments