Skip to content

Commit

Permalink
refactor: add traces to reward fold validator
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhils9 committed Mar 29, 2024
1 parent 2960703 commit eb8f34d
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions src/MultiFold.hs
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,12 @@ prewardSuccessor config configTN nodeCS totalRewardTokens totalStaked state inpu

successorChecks =
pand'List
[ (accNodeF.next #== nodeKey)
, (inputValue <> owedRewardValue <> owedAdaValue) #== pforgetPositive nodeOutputValue
, nodeOutputF.address #== nodeInputF.address
, nodeInDatF.configTN #== configTN
, nodeOutputF.datum #== nodeInputF.datum
, pvalueOfOneScott # nodeCS # inputValue
[ ptraceIfFalse "Incorrect order of nodes" $ (accNodeF.next #== nodeKey)
, ptraceIfFalse "Incorrect reward amount" $ (inputValue <> owedRewardValue <> owedAdaValue) #== pforgetPositive nodeOutputValue
, ptraceIfFalse "Incorrect node output address" $ nodeOutputF.address #== nodeInputF.address
, ptraceIfFalse "Incorrect node configTN" $ nodeInDatF.configTN #== configTN
, ptraceIfFalse "Cannot udpate node datum" $ nodeOutputF.datum #== nodeInputF.datum
, ptraceIfFalse "Does not contain node token" $ pvalueOfOneScott # nodeCS # inputValue
]

accState =
Expand Down Expand Up @@ -729,15 +729,15 @@ prewardFoldNodes = phoistAcyclic $

let foldChecks =
pand'List
[ newFoldNodeF.key #== currFoldNodeF.key
, newDatumF.totalRewardTokens #== totalRewardTokens
, newDatumF.totalStaked #== totalStake
, newDatumF.owner #== datF.owner
, newRewardsFoldState.next #== (toScott $ pfromData newFoldNodeF.next)
, pnormalize # (Value.pforgetPositive ownInputF.value <> owedRewardTknsValue) #== Value.pforgetPositive ownOutputF.value
, (pcountScriptInputs # txIns) #== newRewardsFoldState.foldCount
, currFoldNodeF.configTN #== configTN
, newFoldNodeF.configTN #== configTN
[ ptraceIfFalse "Cannot change key" $ newFoldNodeF.key #== currFoldNodeF.key
, ptraceIfFalse "Cannot change totalRewardTokens" $ newDatumF.totalRewardTokens #== totalRewardTokens
, ptraceIfFalse "Cannot change totalStaked" $ newDatumF.totalStaked #== totalStake
, ptraceIfFalse "Cannot change owner" $ newDatumF.owner #== datF.owner
, ptraceIfFalse "Incorrect next node" $ newRewardsFoldState.next #== (toScott $ pfromData newFoldNodeF.next)
, ptraceIfFalse "Incorrect amount of rewards spent" $ pnormalize # (Value.pforgetPositive ownInputF.value <> owedRewardTknsValue) #== Value.pforgetPositive ownOutputF.value
, ptraceIfFalse "Incorrect script inputs" $ (pcountScriptInputs # txIns) #== newRewardsFoldState.foldCount
, ptraceIfFalse "Incorrect configTN" $ currFoldNodeF.configTN #== configTN
, ptraceIfFalse "Cannot change configTN" $ newFoldNodeF.configTN #== configTN
]
pure $
pif foldChecks (popaque (pconstant ())) perror
Expand Down Expand Up @@ -806,17 +806,17 @@ prewardFoldNode = phoistAcyclic $

let foldChecks =
pand'List
[ currFoldNodeF.key #== newFoldNodeF.key
, currFoldNodeF.next #== nodeInpDatF.key
, newFoldNodeF.next #== nodeInpDatF.next
, foldOutDatumF.totalStaked #== oldTotalStaked
, foldOutDatumF.totalRewardTokens #== oldTotalRewardTokens
, foldOutDatumF.owner #== datF.owner
, (pnoAdaValue # correctOwnOutput) #== (pnoAdaValue #$ pforgetPositive ownOutputF.value)
, correctNodeOutput #== (pforgetPositive nodeOutputF.value)
, nodeInpDatF.configTN #== configTN
, nodeInpDat #== nodeOutDat
, currFoldNodeF.configTN #== configTN
, newFoldNodeF.configTN #== configTN
[ ptraceIfFalse "Cannot change key" $ currFoldNodeF.key #== newFoldNodeF.key
, ptraceIfFalse "Incorrect node folded" $ currFoldNodeF.next #== nodeInpDatF.key
, ptraceIfFalse "Incorrect next node" $ newFoldNodeF.next #== nodeInpDatF.next
, ptraceIfFalse "Cannot change totalStaked" $ foldOutDatumF.totalStaked #== oldTotalStaked
, ptraceIfFalse "Cannot change totalRewardTokens" $ foldOutDatumF.totalRewardTokens #== oldTotalRewardTokens
, ptraceIfFalse "Cannot change owner" $ foldOutDatumF.owner #== datF.owner
, ptraceIfFalse "Incorrect reward spent" $ (pnoAdaValue # correctOwnOutput) #== (pnoAdaValue #$ pforgetPositive ownOutputF.value)
, ptraceIfFalse "Incorrect reward distributed" $ correctNodeOutput #== (pforgetPositive nodeOutputF.value)
, ptraceIfFalse "Incorrect node configTN" $ nodeInpDatF.configTN #== configTN
, ptraceIfFalse "Cannot change node datum" $ nodeInpDat #== nodeOutDat
, ptraceIfFalse "Incorrect input configTN" $ currFoldNodeF.configTN #== configTN
, ptraceIfFalse "Incorrect output configTN" $ newFoldNodeF.configTN #== configTN
]
pure $ pif foldChecks (popaque (pconstant ())) perror

0 comments on commit eb8f34d

Please sign in to comment.