Skip to Content
Looking for Quint Studio docs? Go to studio.quint.sh/onboarding instead.
DocumentationChecking Properties

Checking Properties

🚧️

This page is under construction.

The main way to interact with a Quint model is by checking properties. The simulator can be used to increase the confidence on a property, and model checkers can be used to formally verify them. Properties can also be used to query the model and understand it better, finding interesting scenarios.

Note

The invariant and observation keywords were added in Quint v0.34.0. An update to the latest version is recommended. When an earlier version is used, the docs of v0.33.1  can be read on GitHub.

Properties

Thinking about a system’s properties is not an easy task, but can often be useful to increase understanding in many ways. Writing those properties in Quint enables using the tools (simulator or model checkers) to check that property, or to find out where it doesn’t hold and adjust the model or the expectations about it.

A system might have safety and/or liveness properties.

  • Safety: something bad never happens
    • Examples: balances should never be negative, two different wallets may never hold the same NFT, honest consensus parties may never agree on different values.
  • Liveness: something good eventually happens
    • Examples: eventually all parties decide on a value, eventually termination is detected, eventually a system stabilizes.

It is much easier to write and check safety properties, which can be written as invariants. Liveness properties require temporal formulas, which often rely on assumptions about fairness to be useful, and that may require some hours of study time if you are not familiar already. Also, there are other, more practical, ways to convince ourselves that good things are happening (see below). Safety properties go a long way, start with those. Writing a safety property is as simple as writing a boolean expression:

invariant no_negatives = ADDRESSES.forall(addr => balances.get(addr) >= 0)

balances in this expression (considering the model from the Getting Started guide) is a state variable. While checking no_negatives as an invariant, Quint’s tools will check this expression on every state, meaning it will evaluate it for different values of balances and expect it to always be true. It needs to be true in the initial state and in every possible state that comes from it - it cannot vary, as it is an invariant.

Since no_negatives is declared with invariant, quint run and quint verify check it without any flag.

Using multiple invariants with --invariants

A spec can declare several invariants, and the tools check all of them and report which ones are violated. To check only some of them, or invariants that are not declared with invariant, list them with the --invariants option, which replaces the declared ones. For example, the following two properties are written as plain vals, next to no_negatives:

val accounts_match = balances.keys() == ADDRESSES val total_positive = ADDRESSES.fold(0, (sum, addr) => sum + balances.get(addr)) > 0

All three are listed with --invariants:

quint run bank.qnt --invariants no_negatives accounts_match total_positive

Quint will check all three invariants and report which specific ones are violated:

An example execution: [State 0] { balances: Map("alice" -> 0, "bob" -> 0, "charlie" -> 0) } [violation] Found an issue (34ms at 588 traces/second). ❌ total_positive Use --verbosity=3 to show executions. Use --seed=0x2165520c39f5b7d8 --backend=rust to reproduce. error: Invariant violated

Only total_positive is violated, since every balance is zero in the initial state.

This makes it easier to identify which specific properties are being violated when you have multiple invariants to check.

The --invariants option also works with the verify command, allowing you to check multiple invariants with formal verification:

quint verify bank.qnt --invariants no_negatives accounts_match total_positive

Observations

While invariants are things that need to hold on every state, sometimes we want to check that something is true in some state. This is a sort of sanity check, or reachability check. For that, we define observations.

There are currently two ways to assess reachability of observations with Quint:

  1. For every observation definition in the model, the simulator counts the traces that reach it. Model checkers can also search for them with --search-observations.
  2. When passing --observation flag(s) to quint run or quint verify, the tools will report a trace where the last state satisfies the observation.

Observations are counted in all simulation runs

For (1), you define something that you want to be possible:

observation alice_more_than_bob = balances.get("alice") > balances.get("bob")

The example above states that it should be possible for Alice to have more balance than Bob. This for sure won’t be true for every possible state, but it needs to hold for some of them.

No flag is needed to count it. The same run that checks the invariants counts the traces that reach each observation:

quint run bank.qnt --max-steps=5

Quint reports:

[ok] No violation found (22ms at 454545 traces/second). Checked invariants: no_negatives Trace length statistics: max=6, min=6, average=6.00 You may increase --max-samples and --max-steps. Use --verbosity to produce more (or less) output. Observations: alice_more_than_bob was observed in 7114 trace(s) out of 10000 explored (71.14%) Use --seed=0x18f966d3c3c86e1a --backend=rust to reproduce.

And that informs us that, in most executions, there is a state where Alice has a larger balance than that of Bob.

💡

This is a way to find that “good things are happening” without a liveness property. It is not the same as a liveness property, but it’s a practical alternative that is enough in many scenarios.

When an observation definition is never reached, the simulator prints a warning in place of [ok], but the run does not fail. With --search-observations, quint verify searches for every observation definition once the invariants hold and reports the ones that are not reached in the same way. This is currently not very efficient in the model checkers, and therefore disabled by default. Using the simulator to show reachability should be enough. TLC has recently added support for reachability checks  that can be integrated in the future.

Inspecting traces with --observation

If we concretely want to see a trace that reaches our property, we can ask the simulator to stop at the first trace that reaches it:

quint run bank.qnt --observation=alice_more_than_bob --max-steps=5

Quint reports:

An example execution: [State 0] { balances: Map("alice" -> 0, "bob" -> 0, "charlie" -> 0) } [State 1] { balances: Map("alice" -> 0, "bob" -> 0, "charlie" -> 82) } [State 2] { balances: Map("alice" -> 0, "bob" -> 0, "charlie" -> 35) } [State 3] { balances: Map("alice" -> 62, "bob" -> 0, "charlie" -> 35) } [observed] Observed alice_more_than_bob, which stopped the run (13ms at 77 traces/second). Checked invariants: no_negatives Observations: alice_more_than_bob was observed in 1 trace(s) out of 1 explored (100.00%) Use --seed=0xfcaa6dbf0e8c32f8 --backend=rust to reproduce.

The trace ends at the first state where the property holds. When no trace reaches the property, the run fails with [not observed]. The property can also be given as an expression, such as --observation='balances.get("alice") > 50'.

quint verify takes --observation as well. The model checker then reports a trace of up to --max-steps steps that reaches the observation. When no trace of that length reaches it, the run fails.

Inductive Invariants

An inductive invariant is a special, more powerful kind of invariant. They are a powerful design artifact as they capture the core of why a system is correct. Moreover, inductive invariants enable complete verification without exhaustive state exploration.

How Ordinary Invariants Work

Model checking of ordinary (non-inductive) invariants follows a straightforward but potentially expensive approach:

  1. Check the invariant holds in all initial states
  2. Use the step action and a search strategy (breadth-first, depth-first, etc.) to systematically explore all states reachable from the initial states
  3. Verify the invariant holds in every discovered state

This process may require analyzing arbitrarily long execution sequences. As explained in our Model Checkers documentation, checking ordinary invariants forces you to choose between:

  • Symbolic bounded model checking (Apalache) - Solves constraints representing executions up to a given length, providing incomplete verification results
  • Explicit-state model checking (TLC) - Enumerates all possible states and transitions, which can become computationally intractable for large systems

The Inductive Approach

Inductive invariants use a fundamentally different verification strategy. Instead of verifying an invariant on all reachable states by exploring them explicitly, the approach relies on a stronger inductive invariant to prove the goal invariant. The verification process consists of three steps:

  1. Base case: Verify the inductive invariant holds in all initial states
  2. Inductive step: Prove that if the inductive invariant holds in some state A, then after applying any step transition, the resulting state A’ also satisfies the inductive invariant
  3. Implication: Show that the inductive invariant logically implies the goal invariant

The key insight is that in step 2, state A is not constructed by applying transitions from initial states. Instead, A is any arbitrary state satisfying the inductive invariant’s constraints. Through mathematical induction on steps 1 and 2, we can conclude that the inductive invariant holds on all reachable states without explicitly constructing those states.

Trade-offs and Challenges

While inductive invariants may avoid the state explosion problem, they introduce their own complexities:

  • Finding the right inductive invariant requires expertise and creative insight. Unlike model checking where you simply specify properties to verify, you must construct the strengthened invariant yourself, typically through an iterative process of trial and refinement.
  • To prove your desired property, you typically need to prove something stronger (the inductive invariant), which can feel counterintuitive. The invariant that makes the proof work may require non-obvious insights about the system.

When Inductive Invariants Excel

Inductive invariants become particularly powerful when:

  • Enumerating all reachable states would be computationally prohibitive
  • The inductive invariant’s constraints are well-suited to Apalache’s symbolic reasoning capabilities
  • The system has complex state spaces that resist explicit enumeration

This approach can provide complete verification results even for systems where traditional model checking approaches fail due to state explosion or infinite behaviors.

Checking Inductive Invariants

An inductive invariant ind_inv can be checked with:

quint verify file.qnt --inductive-invariant ind_inv

To also check if ind_inv implies an ordinary invariant inv, run:

quint verify file.qnt --inductive-invariant ind_inv --invariant inv

Simulation (quint run) does not support inductive invariants.

Requirement: “TypeOK”

In order to check an inductive invariant, it has to be constrained enough, otherwise you might see errors like “x is used before it is assigned”. More specifically, for each state variable x, you need to have either:

  1. x == <value>
  2. x.in(<set of possible values>)

We almost always use (2) for inductive invariants. AFTER this constraint, you can write other constraints like x * 2 < 10, but the first time x appears in the predicate, it must be something about its domain. We usually call the predicates that define the domains of variables TypeOK.

How it works

Quint will call Apalache 2-3 times (depending on whether an ordinary invariant was provided):

  1. To check if the inductive invariant holds in all possible initial states (base case). This is the equivalent of calling:
quint verify file.qnt --invariant ind_inv --max-steps 0
  1. To check if, starting from any state where the inductive invariant holds, taking any step results in a state where the invariant still holds. This is the equivalent of calling:
quint verify file.qnt --init ind_inv --invariant ind_inv --max-steps 1

PS: you’d get an error here as ind_inv is not an action, and therefore can’t be used as --init. Using --inductive-invariant takes care of this for you.

  1. To check if, in any state where the inductive invariant holds, the ordinary invariant also holds. This is the equivalent of calling:
quint verify file.qnt --init ind_inv --invariant inv --max-steps 0

Examples

Check out the blog post How to write Inductive Invariants to learn more, and the following examples which include inductive invariants.

  • The algorithm from Lamport’s Teaching Concurrency paper: teaching.qnt 
  • Incrementing a shared counter with a mutex: mutex.qnt 
  • The folklore reliable broadcast protocol explained in the blog post: reliablebc.qnt 
  • The bakery algorithm, with a more complex inductive invariant: bakery.qnt 
  • Dijkstra’s termination detection in a ring: ewd840.qnt 
  • ChonkyBFT agreement (written by Igor Konnov before we added the feature to Quint, so it includes some workarounds): inductive.qnt 
Last updated on