Skip to content

Commit

Permalink
Add anchor data hash checks to remaining governance action commands
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Sep 25, 2024
1 parent 6554786 commit bffa937
Show file tree
Hide file tree
Showing 15 changed files with 304 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ data GovernanceActionUpdateCommitteeCmdArgs era
, returnAddress :: !StakeIdentifier
, proposalUrl :: !ProposalUrl
, proposalHash :: !(L.SafeHash L.StandardCrypto L.AnchorData)
, checkProposalHash :: !(MustCheckHash ProposalUrl)
, oldCommitteeVkeySource :: ![VerificationKeyOrHashOrFileOrScriptHash CommitteeColdKey]
, newCommitteeVkeySource :: ![(VerificationKeyOrHashOrFileOrScriptHash CommitteeColdKey, EpochNo)]
, requiredThreshold :: !Rational
Expand Down Expand Up @@ -99,6 +100,7 @@ data GovernanceActionCreateNoConfidenceCmdArgs era
, returnStakeAddress :: !StakeIdentifier
, proposalUrl :: !ProposalUrl
, proposalHash :: !(L.SafeHash L.StandardCrypto L.AnchorData)
, checkProposalHash :: !(MustCheckHash ProposalUrl)
, mPrevGovernanceActionId :: !(Maybe (TxId, Word16))
, outFile :: !(File () Out)
}
Expand Down Expand Up @@ -130,6 +132,7 @@ data GovernanceActionTreasuryWithdrawalCmdArgs era
, returnAddr :: !StakeIdentifier
, proposalUrl :: !ProposalUrl
, proposalHash :: !(L.SafeHash L.StandardCrypto L.AnchorData)
, checkProposalHash :: !(MustCheckHash ProposalUrl)
, treasuryWithdrawal :: ![(VerificationKeyOrHashOrFile StakeKey, Lovelace)]
, constitutionScriptHash :: !(Maybe ScriptHash)
, outFile :: !(File () Out)
Expand All @@ -145,6 +148,7 @@ data GovernanceActionHardforkInitCmdArgs era
, mPrevGovernanceActionId :: !(Maybe (TxId, Word16))
, proposalUrl :: !ProposalUrl
, proposalHash :: !(L.SafeHash L.StandardCrypto L.AnchorData)
, checkProposalHash :: !(MustCheckHash ProposalUrl)
, protVer :: !L.ProtVer
, outFile :: !(File () Out)
}
Expand All @@ -167,6 +171,7 @@ data UpdateProtocolParametersConwayOnwards era
, returnAddr :: !StakeIdentifier
, proposalUrl :: !ProposalUrl
, proposalHash :: !(L.SafeHash L.StandardCrypto L.AnchorData)
, checkProposalHash :: !(MustCheckHash ProposalUrl)
, governanceActionId :: !(Maybe (TxId, Word16))
, constitutionScriptHash :: !(Maybe ScriptHash)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pUpdateCommitteeCmd eon =
<*> pStakeIdentifier (Just "deposit-return")
<*> pAnchorUrl
<*> pAnchorDataHash
<*> pMustCheckHash proposalHashCheckInfo
<*> many pRemoveCommitteeColdVerificationKeySource
<*> many
( (,)
Expand All @@ -153,6 +154,7 @@ pGovernanceActionNoConfidenceCmd era = do
<*> pStakeIdentifier (Just "deposit-return")
<*> pAnchorUrl
<*> pAnchorDataHash
<*> pMustCheckHash proposalHashCheckInfo
<*> pPreviousGovernanceAction
<*> pFileOutDirection "out-file" "Output filepath of the no confidence proposal."
)
Expand All @@ -174,6 +176,7 @@ pUpdateProtocolParametersPostConway conwayOnwards =
<*> pStakeIdentifier (Just "deposit-return")
<*> pAnchorUrl
<*> pAnchorDataHash
<*> pMustCheckHash proposalHashCheckInfo
<*> pPreviousGovernanceAction
<*> optional pConstitutionScriptHash

Expand Down Expand Up @@ -381,6 +384,7 @@ pGovernanceActionTreasuryWithdrawalCmd era = do
<*> pStakeIdentifier (Just "deposit-return")
<*> pAnchorUrl
<*> pAnchorDataHash
<*> pMustCheckHash proposalHashCheckInfo
<*> some ((,) <$> pStakeVerificationKeyOrHashOrFile (Just "funds-receiving") <*> pTransferAmt)
<*> optional pConstitutionScriptHash
<*> pFileOutDirection "out-file" "Output filepath of the treasury withdrawal."
Expand Down Expand Up @@ -424,6 +428,7 @@ pGovernanceActionHardforkInitCmd era = do
<*> pPreviousGovernanceAction
<*> pAnchorUrl
<*> pAnchorDataHash
<*> pMustCheckHash proposalHashCheckInfo
<*> pPV
<*> pFileOutDirection "out-file" "Output filepath of the hardfork proposal."
)
Expand Down
18 changes: 17 additions & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ runGovernanceActionCreateNoConfidenceCmd
, Cmd.returnStakeAddress
, Cmd.proposalUrl
, Cmd.proposalHash
, Cmd.checkProposalHash
, Cmd.mPrevGovernanceActionId
, Cmd.outFile
} = do
Expand All @@ -141,6 +142,8 @@ runGovernanceActionCreateNoConfidenceCmd
, L.anchorDataHash = proposalHash
}

carryHashChecks checkProposalHash proposalAnchor ProposalCheck

let sbe = conwayEraOnwardsToShelleyBasedEra eon
previousGovernanceAction =
MotionOfNoConfidence $
Expand Down Expand Up @@ -233,6 +236,7 @@ runGovernanceActionUpdateCommitteeCmd
, Cmd.returnAddress
, Cmd.proposalUrl
, Cmd.proposalHash
, Cmd.checkProposalHash
, Cmd.oldCommitteeVkeySource
, Cmd.newCommitteeVkeySource
, Cmd.requiredThreshold
Expand All @@ -252,6 +256,8 @@ runGovernanceActionUpdateCommitteeCmd
, L.anchorDataHash = proposalHash
}

carryHashChecks checkProposalHash proposalAnchor ProposalCheck

oldCommitteeKeyHashes <- forM oldCommitteeVkeySource $ \vkeyOrHashOrTextFile ->
modifyError GovernanceActionsCmdReadFileError $
readVerificationKeyOrHashOrFileOrScriptHash
Expand Down Expand Up @@ -338,6 +344,7 @@ runGovernanceActionCreateProtocolParametersUpdateCmd eraBasedPParams' = do
returnAddr
proposalUrl
proposalHash
checkProposalHash
mPrevGovActId
mConstitutionalScriptHash <-
hoistMaybe (GovernanceActionsValueUpdateProtocolParametersNotFound anyEra) $
Expand All @@ -357,7 +364,10 @@ runGovernanceActionCreateProtocolParametersUpdateCmd eraBasedPParams' = do
{ L.anchorUrl = unProposalUrl proposalUrl
, L.anchorDataHash = proposalHash
}
govAct =

carryHashChecks checkProposalHash proposalAnchor ProposalCheck

let govAct =
UpdatePParams
prevGovActId
updateProtocolParams
Expand Down Expand Up @@ -420,6 +430,7 @@ runGovernanceActionTreasuryWithdrawalCmd
, Cmd.returnAddr
, Cmd.proposalUrl
, Cmd.proposalHash
, Cmd.checkProposalHash
, Cmd.treasuryWithdrawal
, Cmd.constitutionScriptHash
, Cmd.outFile
Expand All @@ -430,6 +441,8 @@ runGovernanceActionTreasuryWithdrawalCmd
, L.anchorDataHash = proposalHash
}

carryHashChecks checkProposalHash proposalAnchor ProposalCheck

depositStakeCredential <-
firstExceptT GovernanceActionsReadStakeCredErrror $
getStakeCredentialFromIdentifier returnAddr
Expand Down Expand Up @@ -469,6 +482,7 @@ runGovernanceActionHardforkInitCmd
, Cmd.mPrevGovernanceActionId
, Cmd.proposalUrl
, Cmd.proposalHash = anchorDataHash
, Cmd.checkProposalHash
, Cmd.protVer
, Cmd.outFile
} = do
Expand All @@ -482,6 +496,8 @@ runGovernanceActionHardforkInitCmd
, L.anchorDataHash
}

carryHashChecks checkProposalHash proposalAnchor ProposalCheck

let sbe = conwayEraOnwardsToShelleyBasedEra eon
govActIdentifier =
L.maybeToStrictMaybe $
Expand Down
Loading

0 comments on commit bffa937

Please sign in to comment.