I'm working through Plutus pioneer homework week 2 file Homework1.hs. I believe I've setup the script correctly, but I find that when running the simulator with a transaction that's expected to fail, the simulator sort of breaks after encountering the validation error. As a reminder, the scripts basically acts like a faucet with "Give" and "Grab" functions, and the validation function is to take two bools and return false if they're not equal to each other. Here's my sequence of transactions:

0: Wallet1 Give 5
1: Wait 1
2: Wallet2 Grab (True, False) // this should fail validation
3: Wait 1
4: Wallet2 Grab (False, False) // should pass
5: Wait 1
6: Wallet1 Give 5
7: Wait 1
8: Wallet2 Grab (True, True) // should pass
9: Wait 1

I'd expect the balances on each step to be:

Genesis: Wallet1 10 Wallet2 10 Script 0
0: Wallet1 5 Wallet2 10 Script 5
2: Wallet1 5 Wallet2 10 Script 5 // Wallet2 fails to Grab
4: Wallet1 5 Wallet2 15 Script 0 // Wallet2 Grabs
6: Wallet1 0 Wallet2 15 Script 5 // Wallet1 Gives
8: Wallet1 0 Wallet2 20 Script 0 // Wallet2 Grabs

But when running in the simulator, it stops at Slot 4, Tx 0 at the top. The Logs however seem to continue to slot 6.

Validating transaction: 4c1f4f09fbfcf30b38e33dcb8759a4c56c7fc1958ccc7f816608fbf49a2fe0a1
Add slot 1
Contract instance for wallet 1: (ReceiveEndpointCall (RawJson "{\"value\":{\"unEndpointValue\":5},\"tag\":\"give\"}"))
Validating transaction: b3e4aae77f5fd3e0a6e2d2b38e80e5971b3a010ae432aa2bf8f576a3ac6c8f1e
Add slot 2
Contract instance for wallet 1: (ContractLog (RawJson "made a gift of 5 lovelace"))
Contract instance for wallet 2: (ReceiveEndpointCall (RawJson "{\"value\":{\"unEndpointValue\":[true,false]},\"tag\":\"grab\"}"))
Validation failed: 033c6c4ae71e507fe66149eb1860cafdebbd7f8eafcd560bed41c400bd275b84
 (ScriptFailure (EvaluationError []))
Add slot 3
Contract instance for wallet 2: (ReceiveEndpointCall (RawJson "{\"value\":{\"unEndpointValue\":[false,false]},\"tag\":\"grab\"}"))
Add slot 4
Contract instance for wallet 1: (ReceiveEndpointCall (RawJson "{\"value\":{\"unEndpointValue\":5},\"tag\":\"give\"}"))
Validating transaction: 217d02eb52b162569b40d20de7f8135ea7ba11f0fab08fd0a80e4f23d6df179e
Add slot 5
Contract instance for wallet 1: (ContractLog (RawJson "made a gift of 5 lovelace"))
Contract instance for wallet 2: (ReceiveEndpointCall (RawJson "{\"value\":{\"unEndpointValue\":[true,true]},\"tag\":\"grab\"}"))
Add slot 6

The other odd thing is that the Balances Carried Forward on Slot 4, Tx 0 (this is as far as the top section runs) shows:

Wallet1 Balance 0
Wallet2 Balance 10
Script Balance 10

Here's a screenshot of the final state of the simulation: Final Simulator State

It's as if the top part of the simulation ignores function calls from any wallet that had a validation error result, and only represents wallets that never had a validation error. I wouldn't expect the Script balance to ever reach 10, as Wallet2 should be able to take 5 lovelace after its first failed Grab.

Is this just a bug in the simulator or do I misunderstand how the simulator / blockchain should work?


1 Answer 1


The problem is that in the off-chain wallet code, after submitting the transaction, there is a line of code that waits for the transaction to be confirmed. Seeing as the transaction is invalid, it will never be confirmed, so the wallet contract blocks on that line forever.

There would be workarounds, but in the final version of Plutus, it will be possible to check the status of validation from the wallet and for example detect if the transaction was invalid.

This means handling this and similar situations will be much easier in future.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.