# Questions about Key State and Consistency

**URL:** <https://forum.canton.network/t/questions-about-key-state-and-consistency/1027>\
**Category:** App Development\
**Created:** [August 12, 2020, 6:16pm UTC](https://forum.canton.network/t/questions-about-key-state-and-consistency/1027 "2020-08-12T18:16:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leonid\_Rozenberg](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/leonid_rozenberg/32/48_2.png) [@Leonid\_Rozenberg](https://forum.canton.network/u/Leonid_Rozenberg)\
**Post date:** [August 12, 2020, 6:16pm UTC](https://forum.canton.network/t/questions-about-key-state-and-consistency/1027/1 "2020-08-12T18:16:07Z")

</div>

I find portions of he [Key Consistency](https://docs.daml.com/concepts/ledger-model/ledger-integrity.html#key-consistency) docs a little bit confusing.

### Why do we need an _unknown_ key state?

"key state"s are defined to be one of three:

- **assigned** to the latest Create | non-consuming Exercise | Fetch action of a contract on said key.
- **free** if the latest action is consuming Exercise | NoSuchKey assertion
- **unknown**.

If there is not last action, why not consider the state as **free**?

### Consistency Q1

“If act is a **Create** action or **NoSuchKey** assertion, then s is **free** or **unknown**.”

… again why not just be **free**? We’re going to great lengths to be precise about things here and that _“or”_ seems odd.

### Consistency Q2

" If act is an **Exercise** or **Fetch** action on some contract c, then s is **assigned** to c or **unknown**."

This time why would it be **unknown**? If we’ve just performed either of those two transactions, shouldn’t the state be **assigned**?

When reading this portion of the documentation, I feel like I’m lacking some assumed piece of background knowledge that I should have already understood. Please let me know if there’s something that would be helpful.

---

<div class="post-metadata">

**Author:** ![oggy](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/oggy/32/109_2.png) [@oggy](https://forum.canton.network/u/oggy)\
**Post date:** [August 13, 2020, 9:25am UTC](https://forum.canton.network/t/questions-about-key-state-and-consistency/1027/2 "2020-08-13T09:25:13Z")

</div>

The current formulation serves to then be able to define internal consistency as follows:

> A transaction is internally consistent if it is internally consistent for all contracts and consistent for all keys.

But your point is valid. Consistency is defined before internal consistency, so I see how it reads like an unnecessary complication at the point of definition. I’ve added this as a todo item in an upcoming change to the keys part of the ledger model write-up:

> <https://github.com/digital-asset/daml/issues/7113>
>
> The Ledger Model documentation currently claims that a \`lookupByKey\` becomes eit…her a \`NoSuchKey\` or \`Fetch\` node, but that's not actually the case. Instead it becomes a \`KeyLookup\` node: https://github.com/digital-asset/daml/blob/master/daml-lf/transaction/src/main/protobuf/com/daml/lf/transaction.proto#L99-L104
> 
> The two are functionally equivalent and it's easier to amend docs over implementation so let's do that.

---

<div class="post-metadata">

**Author:** ![Artur\_Poor](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/artur_poor/32/2442_2.png) [@Artur\_Poor](https://forum.canton.network/u/Artur_Poor)\
**Post date:** [September 21, 2021, 12:30pm UTC](https://forum.canton.network/t/questions-about-key-state-and-consistency/1027/3 "2021-09-21T12:30:18Z")

</div>

Poking this question. I just read the definition of key consistency, and I also tried to figure out Q2 without luck. Any progress on that?
