plutus icon indicating copy to clipboard operation
plutus copied to clipboard

Make CekEvaluationError more informative in ScriptError

Open phadej opened this issue 3 years ago • 11 comments

It would be great to be able to tell whether it was

  • explicit error
  • builtin function invariant violation (e.g. calling equalsInteger with non-integers)
  • "type" error, e.g. trying to apply non-lambda or builtin

EDIT: I was trying to figure out what happens in the evaluation, so ended up traceShow data arguments in applyValidator. After that I used them to evaluateCek manually. That gave me an error like:

        An error has occurred:  User error:
        The provided Plutus code called 'error'.
        Caused by: (force headList [])

And I immediately understood where the problem lies!

(here however Plutus code called error' is slightly incorrect, that's probably a consequence of that expression reducing to error?)

phadej avatar Dec 08 '21 12:12 phadej

And I immediately understood where the problem lies!

@phadej Out of curiosity, what was the problem with force headList []?

srid avatar Dec 08 '21 17:12 srid

@srid me calling head on an empty list, obviously! :)

phadej avatar Dec 08 '21 17:12 phadej

Ah, yes, of course. :-)

I asked only because I'm in the middle of figuring out how to use HeadList properly from UPLC, but the following program (takes a list as argument) throws a CekEvaluationFailure:

Program
  ()
  (Version () 1 0 0)
  (LamAbs
     ()
     (DeBruijn {dbnIndex = 0})
     (Apply
        ()
        (Force () (Builtin () HeadList))
        (Var () (DeBruijn {dbnIndex = 1}))))
Error(eval): EvaluationError [] "(CekEvaluationFailure,Just (Apply () (Force () (Builtin () HeadList)) (Constant () (Some (ValueOf data (List [I 1,I 2,I 3]))))))"

srid avatar Dec 08 '21 17:12 srid

Aha, never mind! Just as I wrote it, I figured out the problem - I was missing a UnListData.

srid avatar Dec 08 '21 17:12 srid

I think it does tell you this... there's some place where I think it gets turned into a string in a way that throws away the information. Was this error coming from the node?

michaelpj avatar Dec 08 '21 17:12 michaelpj

@michaelpj while running EmulatorTrace, I get something like:

      [WARNING] Slot 3: W2e463c8: Validation error: Phase2 1719c980d51347a575fcbbd0bd574f9bd9afd5ccda7f6c0f2c34183fcf4ba7d9: ScriptFailure (EvaluationError [] "CekEvaluationFailure")

which is very terse.

phadej avatar Dec 08 '21 18:12 phadej

hmm, we improved this a bit recently: https://github.com/input-output-hk/plutus/commit/35f6773c6ba8394345000b57e9bf149d092347a1#diff-cb4fae72ab44c8b348c3d0f7dc80d29cc4f3c63805870ab6836ce435caece150R204

Maybe you need a newer plutus version?

michaelpj avatar Dec 09 '21 14:12 michaelpj

Also this whole thing could be less string-y.

michaelpj avatar Dec 09 '21 14:12 michaelpj

Maybe you need a newer plutus version?

I'll test once testnet's cardano-node is updated. (We try to keep dependencies in sync).

phadej avatar Dec 09 '21 15:12 phadej

Wait, is this coming from cardano-node?

michaelpj avatar Dec 09 '21 15:12 michaelpj

@michaelpj no. But its version is pinning its dependencies for us.

phadej avatar Dec 09 '21 15:12 phadej

hmm, we improved this a bit recently: https://github.com/input-output-hk/plutus/commit/35f6773c6ba8394345000b57e9bf149d092347a1#diff-cb4fae72ab44c8b348c3d0f7dc80d29cc4f3c63805870ab6836ce435caece150R204

Seems like the issue was addressed, so I'm closing the ticket.

@phadej please reopen if you still experience the issue.

effectfully avatar Feb 22 '23 18:02 effectfully