<p>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.</p>
<p>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.</p>
<p>This means handling this and similar situations will be much easier in future.</p>

CC BY-SA 4.0
2021-05-03T17:53:18.703Z
Thank you very much Lars!
Spencer MacKinnon
CC BY-SA 4.0
2021-05-03T10:17:23.347Z
2021-05-03T10:17:23.347Z
Lars Brünjes
<p>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 &quot;Give&quot; and &quot;Grab&quot; 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:</p>
<pre><code>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
</code></pre>
<p>I'd expect the balances on each step to be:</p>
<pre><code>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
</code></pre>
<p>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.</p>
<pre><code>Validating transaction: 4c1f4f09fbfcf30b38e33dcb8759a4c56c7fc1958ccc7f816608fbf49a2fe0a1
Add slot 1
Contract instance for wallet 1: (ReceiveEndpointCall (RawJson &quot;{\&quot;value\&quot;:{\&quot;unEndpointValue\&quot;:5},\&quot;tag\&quot;:\&quot;give\&quot;}&quot;))
Validating transaction: b3e4aae77f5fd3e0a6e2d2b38e80e5971b3a010ae432aa2bf8f576a3ac6c8f1e
Add slot 2
Contract instance for wallet 1: (ContractLog (RawJson &quot;made a gift of 5 lovelace&quot;))
Contract instance for wallet 2: (ReceiveEndpointCall (RawJson &quot;{\&quot;value\&quot;:{\&quot;unEndpointValue\&quot;:[true,false]},\&quot;tag\&quot;:\&quot;grab\&quot;}&quot;))
Validation failed: 033c6c4ae71e507fe66149eb1860cafdebbd7f8eafcd560bed41c400bd275b84
 (ScriptFailure (EvaluationError []))
Add slot 3
Contract instance for wallet 2: (ReceiveEndpointCall (RawJson &quot;{\&quot;value\&quot;:{\&quot;unEndpointValue\&quot;:[false,false]},\&quot;tag\&quot;:\&quot;grab\&quot;}&quot;))
Add slot 4
Contract instance for wallet 1: (ReceiveEndpointCall (RawJson &quot;{\&quot;value\&quot;:{\&quot;unEndpointValue\&quot;:5},\&quot;tag\&quot;:\&quot;give\&quot;}&quot;))
Validating transaction: 217d02eb52b162569b40d20de7f8135ea7ba11f0fab08fd0a80e4f23d6df179e
Add slot 5
Contract instance for wallet 1: (ContractLog (RawJson &quot;made a gift of 5 lovelace&quot;))
Contract instance for wallet 2: (ReceiveEndpointCall (RawJson &quot;{\&quot;value\&quot;:{\&quot;unEndpointValue\&quot;:[true,true]},\&quot;tag\&quot;:\&quot;grab\&quot;}&quot;))
Add slot 6
</code></pre>
<p>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:</p>
<pre><code>Wallet1 Balance 0
Wallet2 Balance 10
Script Balance 10
</code></pre>
<p>Here's a screenshot of the final state of the simulation:
<a href="https://i.sstatic.net/nzDY1.png" rel="noreferrer"><img src="https://i.sstatic.net/nzDY1.png" alt="Final Simulator State" /></a></p>
<p>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.</p>
<p>Is this just a bug in the simulator or do I misunderstand how the simulator / blockchain should work?</p>
<p>Thanks!</p>

<simulator>
Blockchain Simulator Chokes on Validation Error
# Blockchain Simulator Chokes on Validation Error

(Asked by: username_0 on 2021-05-02)

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:

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?
Thanks!

**Tags:** simulator

---

## 1 answers

### Answer by username_1 on 2021-05-03. Score: 7 | Accepted answer

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.

> **Comments:**
> **username_0**: Thank you very much Lars!  

---

