I am building a transaction where I use the following function to make my datum and redeemer,
writeJSON :: PlutusTx.ToData a => FilePath -> a -> IO ()
writeJSON file = LBS.writeFile file . encode . scriptDataToJson ScriptDataJsonDetailedSchema . dataToScriptData . PlutusTx.toData
But when I build a transaction to consume an UTxO at the script address I get the following error,
Command failed: transaction build Error: The following scripts have execution failures:
the script for transaction input 0 (in the order of the TxIds) failed with:
The Plutus script evaluation failed: An error has occurred: User error:
The provided Plutus code called 'error'.
Script debugging logs: PT5
I am very certain that my redemeer and datum are correct. My onchain code is the following
data MyDatum = MyDatum
{ pubKey :: Integer
} deriving (Show, Generic, FromJSON, ToJSON, ToSchema)
data MyRedeemer = MyRedeemer
{ privKey :: Integer
} deriving (Show, Generic, FromJSON, ToJSON, ToSchema)
data Params = Params
{ params_p :: Integer
, params_g :: Integer
, params_bits :: Integer
} deriving (Generic, FromJSON, ToJSON, ToSchema)
unsafeParams :: Params
unsafeParams = Params p g 64
where
p = safePrime64
g = (safePrime64 - 1) `PlutusTx.Prelude.divide` 2
PlutusTx.makeIsDataIndexed ''MyDatum [('MyDatum, 0)]
PlutusTx.makeLift ''MyDatum
PlutusTx.makeIsDataIndexed ''MyRedeemer [('MyRedeemer, 0)]
PlutusTx.makeLift ''MyRedeemer
PlutusTx.makeLift ''Params
{-# INLINABLE mkValidator #-}
mkValidator :: Params -> MyDatum -> MyRedeemer -> ScriptContext -> Bool
mkValidator (Params p g _) (MyDatum pub) (MyRedeemer priv) _ = pub == exponentiateMod g priv p
Where the the validator checks whether or not the redeemer is the exponent of the datum via modular exponentiation. Perhaps I incorrectly indexed my datum and redeemer with the makeIsdataIndexed
function?