Skip to content

Commit

Permalink
Merge pull request #1026 from IntersectMBO/jordan/remove-use-of-Scrip…
Browse files Browse the repository at this point in the history
…tWitnessFiles-in-certifying-scripts

Remove use of script witness files in certifying scripts
  • Loading branch information
Jimbo4350 authored Jan 24, 2025
2 parents 002c340 + c62b2b1 commit 22726d5
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 26 deletions.
2 changes: 2 additions & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ library
Cardano.CLI.EraBased.Run.StakePool
Cardano.CLI.EraBased.Run.TextView
Cardano.CLI.EraBased.Run.Transaction
Cardano.CLI.EraBased.Script.Certificate.Read
Cardano.CLI.EraBased.Script.Certificate.Types
Cardano.CLI.EraBased.Script.Mint.Read
Cardano.CLI.EraBased.Script.Mint.Types
Cardano.CLI.EraBased.Script.Spend.Read
Expand Down
13 changes: 9 additions & 4 deletions cardano-cli/src/Cardano/CLI/Compatible/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import Cardano.Api.Shelley hiding (VotingProcedures)
import Cardano.CLI.Environment
import Cardano.CLI.EraBased.Options.Common hiding (pRefScriptFp, pTxOutDatum)
import Cardano.CLI.EraBased.Run.Transaction
import Cardano.CLI.EraBased.Script.Certificate.Read
import Cardano.CLI.EraBased.Script.Certificate.Types
import Cardano.CLI.EraBased.Script.Types
import Cardano.CLI.Parser
import Cardano.CLI.Read
import Cardano.CLI.Types.Common
Expand Down Expand Up @@ -185,7 +188,7 @@ data CompatibleTransactionCmds era
(Maybe NetworkId)
!Coin
-- ^ Tx fee
![(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
![(CertificateFile, Maybe CliCertificateScriptRequirements)]
-- ^ stake registering certs
!(File () Out)

Expand All @@ -203,6 +206,7 @@ data CompatibleTransactionError
| CompatibleVoteError !VoteError
| forall era. CompatibleVoteMergeError !(VotesMergingConflict era)
| CompatibleScriptWitnessError !ScriptWitnessError
| CompatibleScriptWitnessReadError !(FileError CliScriptWitnessError)

instance Error CompatibleTransactionError where
prettyError = \case
Expand All @@ -216,6 +220,7 @@ instance Error CompatibleTransactionError where
CompatibleVoteError e -> pshow e
CompatibleVoteMergeError e -> pshow e
CompatibleScriptWitnessError e -> renderScriptWitnessError e
CompatibleScriptWitnessReadError e -> prettyError e

runCompatibleTransactionCmd
:: forall era
Expand All @@ -240,14 +245,14 @@ runCompatibleTransactionCmd
allOuts <- firstExceptT CompatibleTxCmdError $ mapM (toTxOutInAnyEra sbe) outs

certFilesAndMaybeScriptWits <-
firstExceptT CompatibleScriptWitnessError $
readScriptWitnessFiles sbe certificates
firstExceptT CompatibleScriptWitnessReadError $
readCertificateScriptWitnesses sbe certificates

certsAndMaybeScriptWits :: [(Certificate era, Maybe (ScriptWitness WitCtxStake era))] <-
shelleyBasedEraConstraints sbe $
sequence
[ fmap
(,mSwit)
(,cswScriptWitness <$> mSwit)
( firstExceptT CompatibleFileError . newExceptT $
readFileTextEnvelope AsCertificate (File certFile)
)
Expand Down
7 changes: 4 additions & 3 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import qualified Cardano.Api.Experimental as Exp
import Cardano.Api.Ledger (Coin)
import Cardano.Api.Shelley

import Cardano.CLI.EraBased.Script.Certificate.Types (CliCertificateScriptRequirements)
import Cardano.CLI.EraBased.Script.Mint.Types
import Cardano.CLI.EraBased.Script.Spend.Types (CliSpendScriptRequirements)
import Cardano.CLI.Types.Common
Expand Down Expand Up @@ -71,7 +72,7 @@ data TransactionBuildRawCmdArgs era = TransactionBuildRawCmdArgs
-- ^ Transaction validity upper bound
, fee :: !Coin
-- ^ Transaction fee
, certificates :: ![(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
, certificates :: ![(CertificateFile, Maybe CliCertificateScriptRequirements)]
-- ^ Certificates with potential script witness
, withdrawals :: ![(StakeAddress, Coin, Maybe (ScriptWitnessFiles WitCtxStake))]
, metadataSchema :: !TxMetadataJsonSchema
Expand Down Expand Up @@ -119,7 +120,7 @@ data TransactionBuildCmdArgs era = TransactionBuildCmdArgs
-- ^ Transaction validity lower bound
, mValidityUpperBound :: !(TxValidityUpperBound era)
-- ^ Transaction validity upper bound
, certificates :: ![(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
, certificates :: ![(CertificateFile, Maybe CliCertificateScriptRequirements)]
-- ^ Certificates with potential script witness
, withdrawals :: ![(StakeAddress, Coin, Maybe (ScriptWitnessFiles WitCtxStake))]
-- ^ Withdrawals with potential script witness
Expand Down Expand Up @@ -165,7 +166,7 @@ data TransactionBuildEstimateCmdArgs era = TransactionBuildEstimateCmdArgs
-- ^ Transaction validity lower bound
, mValidityUpperBound :: !(TxValidityUpperBound era)
-- ^ Transaction validity upper bound
, certificates :: ![(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
, certificates :: ![(CertificateFile, Maybe CliCertificateScriptRequirements)]
-- ^ Certificates with potential script witness
, withdrawals :: ![(StakeAddress, Coin, Maybe (ScriptWitnessFiles WitCtxStake))]
-- ^ Withdrawals with potential script witness
Expand Down
40 changes: 35 additions & 5 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import qualified Cardano.Api.Network as Consensus
import Cardano.Api.Shelley

import Cardano.CLI.Environment (EnvCli (..), envCliAnyEon)
import Cardano.CLI.EraBased.Script.Certificate.Types (CliCertificateScriptRequirements)
import qualified Cardano.CLI.EraBased.Script.Certificate.Types as Certifying
import Cardano.CLI.EraBased.Script.Mint.Types
import Cardano.CLI.EraBased.Script.Spend.Types (CliSpendScriptRequirements)
import qualified Cardano.CLI.EraBased.Script.Spend.Types as PlutusSpend
Expand Down Expand Up @@ -1476,7 +1478,7 @@ pTxBuildOutputOptions =

pCertificateFile
:: BalanceTxExecUnits
-> Parser (CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))
-> Parser (CertificateFile, Maybe CliCertificateScriptRequirements)
pCertificateFile balanceExecUnits =
(,)
<$> ( fmap CertificateFile $
Expand All @@ -1488,15 +1490,14 @@ pCertificateFile balanceExecUnits =
<*> optional (pCertifyingScriptOrReferenceScriptWit balanceExecUnits)
where
pCertifyingScriptOrReferenceScriptWit
:: BalanceTxExecUnits -> Parser (ScriptWitnessFiles WitCtxStake)
:: BalanceTxExecUnits -> Parser CliCertificateScriptRequirements
pCertifyingScriptOrReferenceScriptWit bExecUnits =
pScriptWitnessFiles
WitCtxStake
pCertificatePlutusScriptWitness
balanceExecUnits
"certificate"
Nothing
"the use of the certificate."
<|> pPlutusStakeReferenceScriptWitnessFiles "certificate-" bExecUnits
<|> pCertificateReferencePlutusScriptWitness "certificate-" bExecUnits

helpText =
mconcat
Expand All @@ -1505,6 +1506,35 @@ pCertificateFile balanceExecUnits =
, "stake key certificates etc). Optionally specify a script witness."
]

pCertificatePlutusScriptWitness
:: BalanceTxExecUnits -> String -> Maybe String -> String -> Parser CliCertificateScriptRequirements
pCertificatePlutusScriptWitness bExecUnits scriptFlagPrefix scriptFlagPrefixDeprecated help =
Certifying.createSimpleOrPlutusScriptFromCliArgs
<$> pScriptFor
(scriptFlagPrefix ++ "-script-file")
((++ "-script-file") <$> scriptFlagPrefixDeprecated)
("The file containing the script to witness " ++ help)
<*> optional
( (,)
<$> pScriptRedeemerOrFile scriptFlagPrefix
<*> ( case bExecUnits of
AutoBalance -> pure (ExecutionUnits 0 0)
ManualBalance -> pExecutionUnits scriptFlagPrefix
)
)

pCertificateReferencePlutusScriptWitness
:: String -> BalanceTxExecUnits -> Parser CliCertificateScriptRequirements
pCertificateReferencePlutusScriptWitness prefix autoBalanceExecUnits =
Certifying.createPlutusReferenceScriptFromCliArgs
<$> pReferenceTxIn prefix "plutus"
<*> pPlutusScriptLanguage prefix
<*> pScriptRedeemerOrFile (prefix ++ "reference-tx-in")
<*> ( case autoBalanceExecUnits of
AutoBalance -> pure (ExecutionUnits 0 0)
ManualBalance -> pExecutionUnits $ prefix ++ "reference-tx-in"
)

pPoolMetadataFile :: Parser (StakePoolMetadataFile In)
pPoolMetadataFile =
File <$> parseFilePath "pool-metadata-file" "Filepath of the pool metadata."
Expand Down
31 changes: 17 additions & 14 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import Cardano.CLI.EraBased.Commands.Transaction
import qualified Cardano.CLI.EraBased.Commands.Transaction as Cmd
import Cardano.CLI.EraBased.Run.Genesis.Common (readProtocolParameters)
import Cardano.CLI.EraBased.Run.Query
import Cardano.CLI.EraBased.Script.Certificate.Read
import Cardano.CLI.EraBased.Script.Certificate.Types (CertificateScriptWitness (..))
import Cardano.CLI.EraBased.Script.Mint.Read
import Cardano.CLI.EraBased.Script.Mint.Types
import Cardano.CLI.EraBased.Script.Spend.Read
Expand Down Expand Up @@ -161,14 +163,15 @@ runTransactionBuildCmd
readSpendScriptWitnesses eon txins

let spendingScriptWitnesses = mapMaybe (fmap sswScriptWitness . snd) txinsAndMaybeScriptWits

certFilesAndMaybeScriptWits <-
firstExceptT TxCmdScriptWitnessError $ readScriptWitnessFiles eon certificates
firstExceptT TxCmdCliScriptWitnessError $ readCertificateScriptWitnesses eon certificates

-- TODO: Conway Era - How can we make this more composable?
certsAndMaybeScriptWits <-
sequence
[ fmap
(,mSwit)
(,cswScriptWitness <$> mSwit)
( firstExceptT TxCmdReadTextViewFileError . newExceptT $
shelleyBasedEraConstraints eon $
readFileTextEnvelope AsCertificate (File certFile)
Expand Down Expand Up @@ -265,7 +268,7 @@ runTransactionBuildCmd
getAllReferenceInputs
spendingScriptWitnesses
(map mswScriptWitness $ snd usedToGetReferenceInputs)
certsAndMaybeScriptWits
(mapMaybe snd certsAndMaybeScriptWits)
withdrawalsAndMaybeScriptWits
votingProceduresAndMaybeScriptWits
proposals
Expand Down Expand Up @@ -413,8 +416,8 @@ runTransactionBuildEstimateCmd -- TODO change type
readSpendScriptWitnesses sbe txins

certFilesAndMaybeScriptWits <-
firstExceptT TxCmdScriptWitnessError $
readScriptWitnessFiles sbe certificates
firstExceptT TxCmdCliScriptWitnessError $
readCertificateScriptWitnesses sbe certificates

withdrawalsAndMaybeScriptWits <-
firstExceptT TxCmdScriptWitnessError $
Expand Down Expand Up @@ -468,7 +471,7 @@ runTransactionBuildEstimateCmd -- TODO change type
shelleyBasedEraConstraints sbe $
sequence
[ fmap
(,mSwit)
(,cswScriptWitness <$> mSwit)
( firstExceptT TxCmdReadTextViewFileError . newExceptT $
readFileTextEnvelope AsCertificate (File certFile)
)
Expand Down Expand Up @@ -655,8 +658,8 @@ runTransactionBuildRawCmd
readSpendScriptWitnesses eon txIns

certFilesAndMaybeScriptWits <-
firstExceptT TxCmdScriptWitnessError $
readScriptWitnessFiles eon certificates
firstExceptT TxCmdCliScriptWitnessError $
readCertificateScriptWitnesses eon certificates

withdrawalsAndMaybeScriptWits <-
firstExceptT TxCmdScriptWitnessError $
Expand Down Expand Up @@ -715,7 +718,7 @@ runTransactionBuildRawCmd
shelleyBasedEraConstraints eon $
sequence
[ fmap
(,mSwit)
(,cswScriptWitness <$> mSwit)
( firstExceptT TxCmdReadTextViewFileError . newExceptT $
readFileTextEnvelope AsCertificate (File certFile)
)
Expand Down Expand Up @@ -907,7 +910,7 @@ constructTxBodyContent
getAllReferenceInputs
(map sswScriptWitness $ mapMaybe snd inputsAndMaybeScriptWits)
(map mswScriptWitness $ snd valuesWithScriptWits)
certsAndMaybeScriptWits
(mapMaybe snd certsAndMaybeScriptWits)
withdrawals
votingProcedures
proposals
Expand Down Expand Up @@ -1054,7 +1057,7 @@ runTxBuild
getAllReferenceInputs
(map sswScriptWitness $ mapMaybe snd inputsAndMaybeScriptWits)
(map mswScriptWitness $ snd valuesWithScriptWits)
certsAndMaybeScriptWits
(mapMaybe snd certsAndMaybeScriptWits)
withdrawals
votingProcedures
proposals
Expand Down Expand Up @@ -1221,7 +1224,7 @@ validateTxInsReference sbe allRefIns = do
getAllReferenceInputs
:: [ScriptWitness WitCtxTxIn era]
-> [ScriptWitness WitCtxMint era]
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [ScriptWitness WitCtxStake era]
-> [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Proposal era, Maybe (ScriptWitness WitCtxStake era))]
Expand All @@ -1231,14 +1234,14 @@ getAllReferenceInputs
getAllReferenceInputs
spendingWitnesses
mintWitnesses
certFiles
certScriptWitnesses
withdrawals
votingProceduresAndMaybeScriptWits
propProceduresAnMaybeScriptWits
readOnlyRefIns = do
let txinsWitByRefInputs = map getScriptWitnessReferenceInput spendingWitnesses
mintingRefInputs = map getScriptWitnessReferenceInput mintWitnesses
certsWitByRefInputs = [getScriptWitnessReferenceInput sWit | (_, Just sWit) <- certFiles]
certsWitByRefInputs = map getScriptWitnessReferenceInput certScriptWitnesses
withdrawalsWitByRefInputs = [getScriptWitnessReferenceInput sWit | (_, _, Just sWit) <- withdrawals]
votesWitByRefInputs = [getScriptWitnessReferenceInput sWit | (_, Just sWit) <- votingProceduresAndMaybeScriptWits]
propsWitByRefInputs = [getScriptWitnessReferenceInput sWit | (_, Just sWit) <- propProceduresAnMaybeScriptWits]
Expand Down
Loading

0 comments on commit 22726d5

Please sign in to comment.