Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions .agents/skills/quint-modeling/examples/ewd426.qnt
Original file line number Diff line number Diff line change
@@ -1,59 +1,20 @@
/**
* ewd426's Stabilizing Token Ring (EWD426)
* K state machine
* This implementation ensures that from some time on,
* exactly one token circulates in a set of nodes,
*
* Mahtab Norouzi, Josef Widder, Informal Systems, 2024-2025
*/

/* =============================================================================
* quint-modeling REFERENCE EXAMPLE — communication model: SHARED MEMORY
* -----------------------------------------------------------------------------
* Why this is bundled: it is the canonical *shared-memory* shape — there is NO
* message medium. Processes coordinate by reading common state: each node's
* `state_transition` reads its left/right neighbours in `var system: int -> State`.
* Contrast with the Choreo example (tendermint/), which is message-passing.
*
* Demonstrates, against the quint-modeling guidelines:
* - Grouped-map state `var system: int -> State` (one entry per node).
* - Guarded action `step` picks a node that *can* move; no no-op fallback.
* - Logic in pure defs `has_token`, `state_transition`, `count_tokens`.
* - const-instantiation the parametric `self_stabilization` module is run via
* the concrete `ewd426` instance (N = 5, K = 7). This is
* the pattern the skill's spine teaches: a `const` cannot
* run until instantiated. Run with `--main=ewd426`.
* - temporal LIVENESS `convergence` / `closure` / `persistence` — the system
* self-stabilizes to exactly one token. (The only bundled
* example with temporal properties.)
*
* The `broken_ewd426` instance (N = 3, K = 2) is a deliberately-broken config kept for
* contrast — useful to show what a property *failing* looks like.
*
* Verified clean on Quint 0.32.0. See ../examples/README.md for re-verification commands.
* ============================================================================= */
module self_stabilization {
// Number of nodes in the ring
const N: int
const K: int

/// Ensures the state space is larger than the number of nodes
assume _ = K >= N

val bottom = 0
val top = N

/// Mapping of node indices to their states
var system: int -> int

/// Check if a node has the token
pure def has_token(nodes: int -> int, index: int): bool =
if (index == bottom)
nodes.get(bottom) == nodes.get(top)
else
not(nodes.get(index) == nodes.get(index - 1))

/// Update the state of a specific node
pure def state_transition(nodes: int -> int, index: int): int =
if (not(has_token(nodes, index)))
nodes.get(index)
Expand All @@ -62,40 +23,31 @@ module self_stabilization {
else
nodes.get(index - 1)

/// Initialize all nodes with non-deterministic states
action init = all {
nondet initial = 0.to(N).setOfMaps(0.to(K - 1)).oneOf()
system' = initial
}

/// Pick a single active node non-deterministically and update its state
action step = {
nondet node = 0.to(N).filter(i => has_token(system, i)).oneOf()
system' = system.set(node, state_transition(system, node))
}

/// Pick several active nodes non-deterministically and update their state.
/// Closer to the distributed demon is discussed in EWD 391. We are not
/// considering interleaving in the execution of state_transition here
action distributed_step = {
nondet nodes = 0.to(N).filter(i => has_token(system, i)).powerset().exclude(Set()).oneOf()
system' = nodes.fold(system, (s, x) => s.set(x, state_transition(system, x)))
}

// Pure function to count how many tokens exist
pure def count_tokens(nodes: int -> int): int = {
0.to(N).filter(i => has_token(nodes, i)).size()
}

// Temporal properties
temporal convergence = step.weakFair(Set(system)) implies eventually(count_tokens(system) == 1)
temporal closure = always(count_tokens(system) == 1 implies always(count_tokens(system) == 1))
temporal persistence = step.weakFair(Set(system)) implies eventually(always(count_tokens(system) == 1))

// Invariant
def tokenInv = count_tokens(system) > 0

/// to better see the token in the repl
pure def show_token(nodes: int -> int): int -> bool =
nodes.keys().mapBy(i => has_token(nodes, i))
}
Expand All @@ -105,6 +57,5 @@ module ewd426 {
}

module broken_ewd426 {
// This should break the assumption of K >= N. See #1182.
import self_stabilization(N = 3, K = 2).*
}
22 changes: 0 additions & 22 deletions .agents/skills/quint-modeling/examples/tendermint/choreo.qnt
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
/**
* Choreo: Choreograph distributed protocols in Quint
*
* Read the documentation: TODO LINK
*
* Gabriela Moreira, Josef Widder and Yassine Boukhari,
* Informal Systems, 2025
*/

module choreo {
import basicSpells.* from "spells/basicSpells"

// TODO: try moving process id to local context
type LocalState[process_id, ext] = {
process_id: process_id
| ext
Expand All @@ -35,17 +25,14 @@ module choreo {
extensions: ext
}

// This is the message routing to the # handler
type Listener[p, s, m, e, ce, ext] =
(LocalContext[p, s, m, e, ext]) => Set[Transition[p, s, m, e, ce]]

type DeterministicListener[p, s, m, e, ce, ext] =
(LocalContext[p, s, m, e, ext]) => Transition[p, s, m, e, ce]

// Only needed for micro_step
type Input[m, e] = Message(m) | Event(e)

// Only needed for micro_step
type MicroListener[p, s, m, e, ce, ext] =
(LocalContext[p, s, m, e, ext], Input[m, e]) => Set[Transition[p, s, m, e, ce]]

Expand All @@ -59,13 +46,6 @@ module choreo {
| TriggerEvent(e)
| CustomEffect(ce)

/// A displayer is a function that takes a global context and returns a displayable representation of it.
/// This is used to visualize the state of the system for debugging or monitoring purposes.
/// After type instantiation, it should have the following signature:
/// ```
/// (Environment) => Display
/// ```
/// The display type can be anything.
type Displayer[p, s, m, e, ext, d] = (GlobalContext[p, s, m, e, ext]) => d

pure def apply_effect(
Expand Down Expand Up @@ -122,7 +102,6 @@ module choreo {
transitions: Set[Transition[p, s, m, e, ce]],
apply_custom_effect: EffectProcessor[p, s, m, e, ce, extensions],
): bool =
// FIXME: Quint was supposed to detect determinism alone
if (transitions.size() == 1) {
val transition = transitions.getOnlyElement()
val post_env = apply_effect(s, v, transition, apply_custom_effect)
Expand All @@ -139,7 +118,6 @@ module choreo {
apply_custom_effect: EffectProcessor[p, s, m, e, ce, extensions],
displayer: Displayer[p, s, m, e, extensions, d],
): bool =
// FIXME: Quint was supposed to detect determinism alone
if (transitions.size() == 1) {
val transition = transitions.getOnlyElement()
val post_env = apply_effect(s, v, transition, apply_custom_effect)
Expand Down
Loading
Loading