IntersectMBO / plutus

The Plutus language implementation and tools
Apache License 2.0
1.57k stars 479 forks source link

Can't spend script utxo #6610

Open Fiftyw3bs opened 22 hours ago

Fiftyw3bs commented 22 hours ago

I'm trying to spend a utxo are at a script address, but I get the following error message:

      Error :
      -------
      (Slot {getSlot = 6},GenericFail "GYBuildTxException (GYBuildTxBodyErrorAutoBalance (TxBodyScriptExecutionError [(ScriptWitnessIndexTxIn 1,ScriptErrorEvaluationFailed (CekError An error has occurred:\nThe machine terminated because of an error, either from a built-in function or from an explicit use of 'error'.\nCaused by: (unConstrData\n              (B #fea400a92180e63e946ef879e35010ec4c7b622634949597f3584f7c))) [])]))")

I'm not sure what the cause of the issue is, but I best guess is that it may have something to do with the redeemer, as even replacing the validation logic with True doesn't help.

effectfully commented 22 hours ago

The error message says that your code is calling unConstrData over a Data value that is constructed using the B constructor (rather than the Constr one), which is indeed an error. It is likely a business logic error rather than something going wrong on our side. I'll keep this issue open for a bit, but with this amount of info it'll get closed soon.

effectfully commented 22 hours ago

as even replacing the validation logic with True doesn't help.

Hm, maybe I'm wrong. Could you please share the full code?

Fiftyw3bs commented 19 hours ago

Below is the definition of the redeemer

data CommitterIsRequester = CommitterIsRequester 
                          { cirUser1 :: PubKeyHash
                          , cirUser2 :: PubKeyHash
                          , cirUser3 :: PubKeyHash
                          , cirTxOut :: TxOutRef
                          } deriving (Show, Prelude.Eq)
PlutusTx.unstableMakeIsData ''CommitterIsRequester
PlutusTx.makeLift ''CommitterIsRequester

data CommitterIsPerformer = CommitterIsPerformer 
                          { cipUser4 :: PubKeyHash
                          , cipTxOut :: TxOutRef
                          } deriving (Show, Prelude.Eq)
PlutusTx.unstableMakeIsData ''CommitterIsPerformer
PlutusTx.makeLift ''CommitterIsPerformer

data CommittedBy = RequesterCommitted CommitterIsRequester
                 | PerformerCommitted CommitterIsPerformer
                 deriving (Show, Prelude.Eq)
-- PlutusTx.makeIsDataIndexed ''CommittedBy [ ('RequesterCommitted, 9), ('PerformerCommitted, 10) ]
-- PlutusTx.makeLift ''CommittedBy
PlutusTx.unstableMakeIsData ''CommittedBy
PlutusTx.makeLift ''CommittedBy

data StepAction = Claim
                | Commit CommittedBy
                | Commence
                -- | Confirm
                | Delegate
                | Fulfill
                | Refund
                | InvokeConflictResolution PlutusV2.PubKeyHash
                | ResolveConflict
                 deriving (Show, Prelude.Eq)
PlutusTx.makeIsDataIndexed ''StepAction [ 
                                          ('Claim, 0), ('Commit, 1)
                                        , ('Commence, 2) --, ('Confirm, 3)
                                        , ('Delegate, 4), ('Fulfill, 5)
                                        , ('Refund, 6), ('InvokeConflictResolution, 7)
                                        , ('ResolveConflict, 8)
                                        ]
PlutusTx.unstableMakeIsData ''StepAction
PlutusTx.makeLift ''StepAction

When I make use of PlutusTx.makeIsDataIndexed:

PlutusTx.makeIsDataIndexed ''CommittedBy [ ('RequesterCommitted, 9), ('PerformerCommitted, 10) ]
PlutusTx.makeLift ''CommittedBy

The error message becomes:

Error :
      -------
      (Slot {getSlot = 6},GenericFail "GYBuildTxException (GYBuildTxBodyErrorAutoBalance (TxBodyScriptExecutionError [(ScriptWitnessIndexTxIn 1,ScriptErrorEvaluationFailed (CekError An error has occurred:\nThe machine terminated because of an error, either from a built-in function or from an explicit use of 'error'.) [\"PT1\"])]))")

It works fine when the validator directly returns True:

{-# INLINABLE mkStepValidator #-}
mkStepValidator :: StepSettings -> Step -> StepAction -> PlutusV2.ScriptContext -> Bool
mkStepValidator StepSettings{..} st@Step{..} sa ctx = True

But returns the error message if it is implemented so:

{-# INLINABLE mkStepValidator #-}
mkStepValidator :: StepSettings -> Step -> StepAction -> PlutusV2.ScriptContext -> Bool
mkStepValidator StepSettings{..} st@Step{..} sa ctx =
  let info :: PlutusV2.TxInfo
      info = PlutusV2.scriptContextTxInfo ctx

      ...
    in
      case sa of
        Commit committer    -> True
        _ -> True
effectfully commented 17 hours ago

Thank you, we'll look into it.

zliu41 commented 15 hours ago

I don't think there's anything wrong with your redeemer definition, but the actual redeemer submitted in your transaction must match it, and it seems like it doesn't. I'd examine the code where you construct the transaction.