# Message and code verification

**URL:** <https://forum.dfinity.org/t/message-and-code-verification/1373>\
**Category:** Developers\
**Created:** [October 5, 2020, 3:45am UTC](https://forum.dfinity.org/t/message-and-code-verification/1373 "2020-10-05T03:45:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![wang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/wang/32/446_2.png) [@wang](https://forum.dfinity.org/u/wang)\
**Post date:** [October 5, 2020, 3:45am UTC](https://forum.dfinity.org/t/message-and-code-verification/1373/1 "2020-10-05T03:45:37Z")

</div>

**Message verification**

How do I verify that an update message was accepted, and that the expected state transition has occurred? @enzo you mentioned merkle proofs being an option, do we have any clarity on what that will look like?

**Code verification**

How do I verify that the canister I’m interacting with does what I think it does? Assuming the code is open source, how do I check that the compiled Wasm matches the deployed actor? Something like a `retrieve` function for all canisters should work.

---

<div class="post-metadata">

**Author:** ![wang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/wang/32/446_2.png) [@wang](https://forum.dfinity.org/u/wang)\
**Post date:** [October 8, 2020, 2:54am UTC](https://forum.dfinity.org/t/message-and-code-verification/1373/2 "2020-10-08T02:54:55Z")

</div>

Another question:

**Message ordering**

I believe messages in a block are first ordered and then executed, right? How is the message order determined?

---

<div class="post-metadata">

**Author:** ![max](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/max/32/491_2.png) [@max](https://forum.dfinity.org/u/max)\
**Post date:** [October 8, 2020, 8:14am UTC](https://forum.dfinity.org/t/message-and-code-verification/1373/3 "2020-10-08T08:14:46Z")

</div>

Hello Norton,

First, a clarification: Update queries go through consensus. Read only queries don’t need to wait so the following does not apply to them.

I believe that update messages are executed on a first come, first served basis, with the caveat that there may be some reordering before the messages get to the selection. There is not, at present, any fancy ordering. Many canisters do run in parallel though, so messages to different canisters are quite likely to be executed out of order.

Note: Given that the order is not guaranteed, if you care about the ordering either the canister needs to enforce ordering or the caller needs to verify that one message has completed before sending the next.

Best wishes, Max

---

<div class="post-metadata">

**Author:** ![max](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/max/32/491_2.png) [@max](https://forum.dfinity.org/u/max)\
**Post date:** [October 8, 2020, 8:24am UTC](https://forum.dfinity.org/t/message-and-code-verification/1373/4 "2020-10-08T08:24:33Z")

</div>

Regarding the status of a message, is this what you are looking for? [https://sdk.dfinity.org/docs/developers-guide/cli-reference/dfx-canister.html#\_dfx\_canister\_request\_status](https://sdk.dfinity.org/docs/developers-guide/cli-reference/dfx-canister.html#_dfx_canister_request_status)

---

<div class="post-metadata">

**Author:** ![wang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/wang/32/446_2.png) [@wang](https://forum.dfinity.org/u/wang)\
**Post date:** [October 8, 2020, 8:49am UTC](https://forum.dfinity.org/t/message-and-code-verification/1373/5 "2020-10-08T08:49:23Z")

</div>

Right, I’m only referring to update queries here. My concern is the classic front running problem - assuming a malicious replica can read the contents of my message, it can reorder the pending messages (and add its own messages) for its own benefit. One way to prevent this is to commit to an order _before_ execution, so the malicious replica doesn’t know which messages it can frontrun.

Regarding message verification, I’m asking how I can verify that my expected state transition `S -> S'` occurred, without any unintended side effects.

---

<div class="post-metadata">

**Author:** ![PaulLiu](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulliu/32/4701_2.png) [@PaulLiu](https://forum.dfinity.org/u/PaulLiu)\
**Post date:** [October 8, 2020, 4:43pm UTC](https://forum.dfinity.org/t/message-and-code-verification/1373/6 "2020-10-08T16:43:56Z")

</div>

> One way to prevent this is to commit to an order _before_ execution

Execution has to be deterministic across all replicas. Modifying execution order on a single replica will only lead to a state that is different than other replicas, and hence it won’t be certified.

What a malicious operator can do is to purposely craft a block to use a certain order for their own benefit. However, because block makers are randomly selected, so the effect of doing this to target attack a certain user or a certain canister is limited.

What a malicious operator can also do is to favor one block over another during notary sigining. But this is also likely to have any effect because (1) the rank of blocks are also randomly determined, and (2) a block is fully notarized when it gets majority signatures, so it is unlikely that majority are all malicious.

Does the above answer your question?

---

<div class="post-metadata">

**Author:** ![wang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/wang/32/446_2.png) [@wang](https://forum.dfinity.org/u/wang)\
**Post date:** [October 8, 2020, 5:01pm UTC](https://forum.dfinity.org/t/message-and-code-verification/1373/7 "2020-10-08T17:01:55Z")

</div>

Ah right, I forgot about the random block makers, that answers my question.

Is there a way for a malicious actor (not replica) front run a message? They would have to be broadcasted that message relatively early, and then broadcast their own message faster, somehow.

---

<div class="post-metadata">

**Author:** ![pie-silo](https://avatars.discourse-cdn.com/v4/letter/p/f19dbf/32.png) [@pie-silo](https://forum.dfinity.org/u/pie-silo)\
**Post date:** [October 9, 2020, 5:09pm UTC](https://forum.dfinity.org/t/message-and-code-verification/1373/8 "2020-10-09T17:09:12Z")

</div>

So a malicious operator could give a malicious response to a query request?

---

<div class="post-metadata">

**Author:** ![PaulLiu](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulliu/32/4701_2.png) [@PaulLiu](https://forum.dfinity.org/u/PaulLiu)\
**Post date:** [October 15, 2020, 2:55am UTC](https://forum.dfinity.org/t/message-and-code-verification/1373/9 "2020-10-15T02:55:27Z")

</div>

> So a malicious operator could give a malicious response to a query request?

Yes, it indeed is a valid attack. IC can mitigate this attack in a number of ways, including offering partially verifiable replies for query calls, Such advanced features have yet to be made fully accessible to developers.

As a fallback, one can just use update calls if high degree of security is required.
