-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add version of Voting.tla that can be analyzed by Apalache. #112
Draft
nano-o
wants to merge
8
commits into
tlaplus:master
Choose a base branch
from
nano-o:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a9a134c
Add version of Voting.tla that can be analyzed by Apalache.
nano-o 528db1d
remove comment above reusing Voting.tla
nano-o 26a4582
update README and add VotingApalache to manifest.json
nano-o 681565c
Mention that Apalache is installed in the devcontainer
nano-o fe909ed
Add forgotten definition of Spec
nano-o b95e74b
Use a separate MC file for checking VotingApalache with Apalache
nano-o 05ebed1
improve comments
nano-o fb0b1d8
rename files
nano-o File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--------------------------- MODULE MCVotingApalache ------------------------------- | ||
|
||
EXTENDS Integers | ||
|
||
Value == {"V1_OF_VALUE","V2_OF_VALUE"} | ||
Acceptor == {"A1_OF_ACCEPTOR","A2_OF_ACCEPTOR","A3_OF_ACCEPTOR"} | ||
\* The quorums are the sets of 2 acceptors: | ||
Quorum == { | ||
{"A1_OF_ACCEPTOR","A2_OF_ACCEPTOR"}, | ||
{"A1_OF_ACCEPTOR","A3_OF_ACCEPTOR"}, | ||
{"A2_OF_ACCEPTOR","A3_OF_ACCEPTOR"}} | ||
|
||
MaxBal == 2 | ||
Ballot == 0..MaxBal \* NOTE: has to be finite for `^Apalache^' because it is used as the domain of a function | ||
|
||
VARIABLES | ||
\* @type: ACCEPTOR -> Set(<<Int,VALUE>>); | ||
votes, | ||
\* @type: ACCEPTOR -> Int; | ||
maxBal | ||
|
||
INSTANCE VotingApalache | ||
|
||
\* To install `^Apalache,^' see the `^Apalache^' website at `^https://apalache.informal.systems/^'. | ||
\* Note that this is not necessary if you are using the devcontainer, as `^Apalache,^' is already installed. | ||
\* To check that the invariant holds initially, run: | ||
\* apalache-mc check --init=Init --inv=Invariant --length=0 MCVotingApalache.tla | ||
\* To check that the invariant is preserved, run: | ||
\* apalache-mc check '--tuning-options=search.invariantFilter=1->.*' --init=Invariant --inv=Invariant --length=1 MCVotingApalache.tla | ||
|
||
=================================================================================== | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
------------------------------- MODULE VotingApalache ------------------------------- | ||
|
||
(***********************************************************************************) | ||
(* This is a version of `^Voting.tla^' that can be analyzed by the `^Apalache^' *) | ||
(* model-checker. Here are the differences compared to `^Voting.tla^': *) | ||
(* *) | ||
(* * We make Ballot a constant in order to be able to substitute a finite set. *) | ||
(* *) | ||
(* * We rewrite SafeAt and ShowsSafeAt to avoid ranges of integers with *) | ||
(* non-constant bounds (which `^Apalache^' does not support). *) | ||
(* *) | ||
(* We also give an inductive invariant that proves the consistency property. On a *) | ||
(* desktop computer from 2022, `^Apalache^' takes 1 minute and 45 seconds to check *) | ||
lemmy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(* that the invariant is inductive when there are 3 values, 3 processes, and 4 *) | ||
(* ballots. For model-checking with `^Apalache,^'see `^MCVotingApalache.tla^'. *) | ||
(***********************************************************************************) | ||
|
||
EXTENDS Integers | ||
|
||
CONSTANTS | ||
Value, | ||
Acceptor, | ||
Quorum, | ||
Ballot | ||
|
||
VARIABLES | ||
votes, | ||
maxBal | ||
|
||
TypeOK == | ||
/\ votes \in [Acceptor -> SUBSET (Ballot\times Value)] | ||
/\ maxBal \in [Acceptor -> Ballot\cup {-1}] | ||
|
||
VotedFor(a, b, v) == <<b, v>> \in votes[a] | ||
|
||
ChosenAt(b, v) == | ||
\E Q \in Quorum : \A a \in Q : VotedFor(a, b, v) | ||
|
||
chosen == {v \in Value : \E b \in Ballot : ChosenAt(b, v)} | ||
|
||
DidNotVoteAt(a, b) == \A v \in Value : ~ VotedFor(a, b, v) | ||
|
||
CannotVoteAt(a, b) == /\ maxBal[a] > b | ||
/\ DidNotVoteAt(a, b) | ||
NoneOtherChoosableAt(b, v) == | ||
\E Q \in Quorum : | ||
\A a \in Q : VotedFor(a, b, v) \/ CannotVoteAt(a, b) | ||
|
||
SafeAt(b, v) == \A c \in Ballot : c < b => NoneOtherChoosableAt(c, v) | ||
|
||
ShowsSafeAt(Q, b, v) == | ||
/\ \A a \in Q : maxBal[a] \geq b | ||
\* NOTE: `^Apalache^' does not support non-constant integer ranges (e.g. we cannot write (c+1)..(b-1)) | ||
/\ \E c \in Ballot\cup {-1} : | ||
/\ c < b | ||
/\ (c # -1) => \E a \in Q : VotedFor(a, c, v) | ||
/\ \A d \in Ballot : c < d /\ d < b => \A a \in Q : DidNotVoteAt(a, d) | ||
|
||
Init == | ||
/\ votes = [a \in Acceptor |-> {}] | ||
/\ maxBal = [a \in Acceptor |-> -1] | ||
|
||
IncreaseMaxBal(a, b) == | ||
/\ b > maxBal[a] | ||
/\ maxBal' = [maxBal EXCEPT ![a] = b] | ||
/\ UNCHANGED votes | ||
|
||
VoteFor(a, b, v) == | ||
/\ maxBal[a] \leq b | ||
/\ \A vt \in votes[a] : vt[1] # b | ||
/\ \A c \in Acceptor \ {a} : | ||
\A vt \in votes[c] : (vt[1] = b) => (vt[2] = v) | ||
/\ \E Q \in Quorum : ShowsSafeAt(Q, b, v) | ||
/\ votes' = [votes EXCEPT ![a] = @ \cup {<<b, v>>}] | ||
/\ maxBal' = [maxBal EXCEPT ![a] = b] | ||
|
||
Next == \E a \in Acceptor, b \in Ballot : | ||
\/ IncreaseMaxBal(a, b) | ||
\/ \E v \in Value : VoteFor(a, b, v) | ||
|
||
Spec == Init /\ [][Next]_<<votes, maxBal>> | ||
|
||
(********************************************************************************) | ||
(* Next, we define an inductive invariant that shows consistency. We reuse *) | ||
(* definitions from Voting.tla and add the property NoVoteAfterMaxBal, which is *) | ||
(* needed to make the invariant inductive. *) | ||
(********************************************************************************) | ||
|
||
VotesSafe == \A a \in Acceptor, b \in Ballot, v \in Value : | ||
VotedFor(a, b, v) => SafeAt(b, v) | ||
|
||
OneValuePerBallot == | ||
\A a1, a2 \in Acceptor, b \in Ballot, v1, v2 \in Value : | ||
VotedFor(a1, b, v1) /\ VotedFor(a2, b, v2) => (v1 = v2) | ||
|
||
NoVoteAfterMaxBal == \A a \in Acceptor, b \in Ballot, v \in Value : | ||
<<b,v>> \in votes[a] => /\ b <= maxBal[a] | ||
|
||
Consistency == \A v,w \in chosen : v = w | ||
|
||
\* This invariant is inductive and establishes consistency: | ||
Invariant == | ||
/\ TypeOK | ||
/\ VotesSafe | ||
/\ OneValuePerBallot | ||
/\ NoVoteAfterMaxBal | ||
/\ Consistency | ||
Invariant_ == Invariant | ||
|
||
===================================================================================== |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elsewhere, we recently discussed TLA+ naming conventions.
MC*Apalache
is really verbose. Perhaps, we want to adopt and encourage a less verbose convention? IIRC, Apalache already prefixes some operators withApa
. So how aboutApaMCVoting
orAPAMCVoting
? Would then even be the same number of chars if users want to doAPAMCVoting
andTLCMCVoting
. On the other hand, we might just as well dropMC
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
MC
prefix seems superfluous in that case. In this particular example, do you have a suggestion for the name of the specification module?Voting2.tla
andApaVoting2.tla
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ApaVoting2
andTLCVoting2
looks like a sensible convention to me. If one want to distinguish between different modes, she can add a prefix likeTLCSimVoting2
to tag this module for simulation.By the way, the VSCode extension simulates a model/config pair whenever the prefix
Smoke*
is used. This happens when the editor is saved. Once we establish a convention, we can integrate similar functionalities like type checking.