<blockquote>
<p>Is this function then used as a sort of predicate on every attempted
transition to a new state?</p>
</blockquote>
<p>Yes, this is why we include the following line</p>
<pre><code>check _ _ _ _ _ = True
</code></pre>
<p>You can find docs for <code>smCheck</code> here <a href="https://playground.plutus.iohkdev.io/tutorial/haddock/plutus-contract/html/Language-Plutus-Contract-StateMachine-OnChain.html#v:smCheck" rel="nofollow noreferrer">https://playground.plutus.iohkdev.io/tutorial/haddock/plutus-contract/html/Language-Plutus-Contract-StateMachine-OnChain.html#v:smCheck</a></p>
<blockquote>
<p>Additionally, is this an example of pattern matching to the specific case where the transaction includes a redeemer and nonce?</p>
</blockquote>
<p>Yes, the logic will be run only if both players made their moves (1st player put hashed version of his move, 2nd player Zero or One) and if the first player wants to prove that he can withdraw the money.</p>

CC BY-SA 4.0
2021-06-09T16:33:44.417Z
2021-06-09T16:33:44.417Z
Yanis Urbis
<p>In the PPP lecture 7 state machines are introduced. They are used to make the guessing game more concise.</p>
<p>One of the situations is where the first player has won and needs to prove their guess by providing the nonce they originally used to hash the guess. A function was written for this named <code>check</code></p>
<pre><code>check :: ByteString -&gt; ByteString -&gt; GameDatum -&gt; GameRedeemer -&gt; ScriptContext -&gt; Bool
check bsZero' bsOne' (GameDatum bs (Just c)) (Reveal nonce) _ =
    sha2_256 (nonce `concatenate` if c == Zero then bsZero' else bsOne') == bs
check _       _      _                       _              _ = True
</code></pre>
<p>This function is then assigned in the StateMachine definition as the <code>smCheck</code>.</p>
<p>Is this function then used as a sort of predicate on every attempted transition to a new state?</p>
<p>Additionally, is this an example of pattern matching to the specific case where the transaction includes a redeemer and nonce?</p>
<p>Thanks!</p>

<plutus><plutus-pioneer-program><statemachines>
How does smCheck work?
# How does smCheck work?

(Asked by: username_0 on 2021-06-09)

In the PPP lecture 7 state machines are introduced. They are used to make the guessing game more concise.
One of the situations is where the first player has won and needs to prove their guess by providing the nonce they originally used to hash the guess. A function was written for this named check
check :: ByteString -> ByteString -> GameDatum -> GameRedeemer -> ScriptContext -> Bool
check bsZero' bsOne' (GameDatum bs (Just c)) (Reveal nonce) _ =
    sha2_256 (nonce `concatenate` if c == Zero then bsZero' else bsOne') == bs
check _       _      _                       _              _ = True

This function is then assigned in the StateMachine definition as the smCheck.
Is this function then used as a sort of predicate on every attempted transition to a new state?
Additionally, is this an example of pattern matching to the specific case where the transaction includes a redeemer and nonce?
Thanks!

**Tags:** plutus, plutus-pioneer-program, statemachines

---

## 1 answers

### Answer by username_1 on 2021-06-09. Score: 1 | Accepted answer

Is this function then used as a sort of predicate on every attempted
transition to a new state?

Yes, this is why we include the following line
check _ _ _ _ _ = True

You can find docs for smCheck here https://playground.plutus.iohkdev.io/tutorial/haddock/plutus-contract/html/Language-Plutus-Contract-StateMachine-OnChain.html#v:smCheck

Additionally, is this an example of pattern matching to the specific case where the transaction includes a redeemer and nonce?

Yes, the logic will be run only if both players made their moves (1st player put hashed version of his move, 2nd player Zero or One) and if the first player wants to prove that he can withdraw the money.


---

