Skip to content
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 Quint model of Interchain Security #1336

Merged
merged 81 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
e2b6407
Start new attempt on Quint model of ICS
p-offtermatt Aug 17, 2023
283dc0a
Advance quint model
p-offtermatt Aug 23, 2023
2155a4f
Add first finished draft of model
p-offtermatt Aug 24, 2023
6ca6510
Add test run to model
p-offtermatt Aug 25, 2023
e27e74b
Rename model, add test, use powerset for nondeterminism
p-offtermatt Aug 25, 2023
50fae34
Reintroduce vsc changed tracking variables
p-offtermatt Aug 25, 2023
78e890a
Add text with what expliticly is modelled
p-offtermatt Aug 25, 2023
a1d57ef
Add bluespec to ccv.qnt
p-offtermatt Aug 25, 2023
6c91866
Add bluespec to expraSpells.qnt
p-offtermatt Aug 25, 2023
2126eac
Add docstring to extraSpells module
p-offtermatt Sep 5, 2023
1320b95
Start rewriting model
p-offtermatt Sep 18, 2023
5fa449c
Revert "Start rewriting model"
p-offtermatt Sep 18, 2023
c05d9e6
Start rewriting quint model
p-offtermatt Sep 18, 2023
4bbe033
Continue seperating logic in Quint model
p-offtermatt Sep 19, 2023
5ebab39
Start debugging cryptic error message
p-offtermatt Sep 20, 2023
5bca6fc
Start adding endAndBeginBlock defs
p-offtermatt Sep 20, 2023
4f77d68
Diagnose Quint parser bug
p-offtermatt Sep 21, 2023
fa233d6
Fix type in Quint
p-offtermatt Sep 21, 2023
66663bf
Add endBlock actions
p-offtermatt Sep 21, 2023
7b489fe
Start adding state machine module
p-offtermatt Sep 26, 2023
b992f8c
Save status with crashing effect checker
p-offtermatt Sep 26, 2023
baaddb7
Resolve issue by removing undefined field
p-offtermatt Sep 26, 2023
2c1341d
Remove add
p-offtermatt Sep 27, 2023
e09968d
Fix init
p-offtermatt Sep 27, 2023
55ab595
Snapshot spec with parser crasher
p-offtermatt Sep 28, 2023
0897e8c
Snapshot model
p-offtermatt Sep 28, 2023
d227aee
Start debugging tests
p-offtermatt Sep 28, 2023
09b1b87
Finish test for quint model
p-offtermatt Sep 28, 2023
96c101f
Add README and improve folder structure
p-offtermatt Sep 29, 2023
aa2989e
Fix import
p-offtermatt Sep 29, 2023
c291303
Add some invariants
p-offtermatt Sep 29, 2023
94a0acb
Refactor Consumer advancement
p-offtermatt Sep 29, 2023
8818531
Snapshot error
p-offtermatt Sep 29, 2023
633f8bb
Make time module upper case
p-offtermatt Sep 29, 2023
f28d074
Add invariants
p-offtermatt Sep 29, 2023
c0363f2
Clean up invariants
p-offtermatt Sep 29, 2023
b9d8caf
Add script to run many invariants
p-offtermatt Sep 29, 2023
e494a09
Update model
p-offtermatt Oct 2, 2023
289ccad
Update model for bug reporting]
p-offtermatt Oct 2, 2023
45cfc5c
Remove sanity check script
p-offtermatt Oct 2, 2023
4fdc2ff
Fix model and randomly run invariant checks
p-offtermatt Oct 2, 2023
99744ff
Remove trace
p-offtermatt Oct 2, 2023
1bc4610
Add model checking to README
p-offtermatt Oct 2, 2023
9e4f9c4
Add bluespec
p-offtermatt Oct 2, 2023
ca50ee2
Try fixed bluespec
p-offtermatt Oct 2, 2023
a80ce70
Fix bluespec definitions
p-offtermatt Oct 2, 2023
918e71a
Update tests/difference/core/quint_model/README.md
p-offtermatt Oct 5, 2023
8da4cfe
Update tests/difference/core/quint_model/README.md
p-offtermatt Oct 5, 2023
2a68236
Fix minor issues
p-offtermatt Oct 5, 2023
2ad4deb
Update tests/difference/core/quint_model/README.md
p-offtermatt Oct 6, 2023
9d40842
Update tests/difference/core/quint_model/README.md
p-offtermatt Oct 6, 2023
3eeb3fd
Update tests/difference/core/quint_model/README.md
p-offtermatt Oct 6, 2023
2000272
Correct verify command by adding \
p-offtermatt Oct 6, 2023
7cd826b
Add Inv to ValidatorUpdatesArePropagated
p-offtermatt Oct 6, 2023
7df2b1f
Update tests/difference/core/quint_model/README.md
p-offtermatt Oct 6, 2023
3633dc4
Apply comments
p-offtermatt Oct 10, 2023
dc7e687
Rename VSC to Vsc
p-offtermatt Oct 10, 2023
728b024
Return plain ProtocolState in cases where no error is returned anyways
p-offtermatt Oct 10, 2023
641d845
Remove unused defs
p-offtermatt Oct 10, 2023
c2aa6d0
Fix indentation
p-offtermatt Oct 10, 2023
75b1e11
Rename to isRunningConsumer
p-offtermatt Oct 10, 2023
f46554b
Unify naming for extraSpells
p-offtermatt Oct 10, 2023
3630846
Remove HasSubsequence
p-offtermatt Oct 10, 2023
90f6652
Run tests before running invariants
p-offtermatt Oct 10, 2023
13a32fc
Rename modules to have same name as files
p-offtermatt Oct 11, 2023
852dac4
Adjust module name in README and invariant script
p-offtermatt Oct 11, 2023
8aee401
Fix voting power change behaviour around 0
p-offtermatt Oct 11, 2023
d75d5c5
Adjust error message in test
p-offtermatt Oct 11, 2023
f294eec
Remove special treatment of 0 voting power
p-offtermatt Oct 11, 2023
4d87372
Rename sentVscPackets to sentVscPacketsToConsumer
p-offtermatt Oct 12, 2023
53d5bff
Update tests/difference/core/quint_model/README.md
p-offtermatt Oct 12, 2023
738a347
Resolve comments
p-offtermatt Oct 12, 2023
c7fe7c5
Merge branch 'ph/quint-model-v2' of https://github.com/cosmos/interch…
p-offtermatt Oct 12, 2023
3a03fcd
Adjust comment to fit actual time advancement
p-offtermatt Oct 12, 2023
d71dad3
Remove hasError field and make it a function
p-offtermatt Oct 13, 2023
455696a
Adjust docstring
p-offtermatt Oct 13, 2023
d422cb4
Remove unused timedout val
p-offtermatt Oct 13, 2023
6ed82c8
Update doc
p-offtermatt Oct 13, 2023
b817f43
Rename statemachine to model
p-offtermatt Oct 16, 2023
70cd774
Use ... syntax
p-offtermatt Oct 16, 2023
86324b7
Change Error type to string
p-offtermatt Oct 16, 2023
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
72 changes: 72 additions & 0 deletions tests/difference/core/quint_model/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
This folder contains a Quint model for the core logic of Cross-Chain Validation (CCV).

### File structure
The files are as follows:
- ccv.qnt: Contains the type definitions, data structures, functional logic for CCV.
The core of the protocol.
- ccv_statemachine.qnt: Contains the state machine layer for CCV. Very roughly speaking, this could be seen as "e2e tests".
p-offtermatt marked this conversation as resolved.
Show resolved Hide resolved
Also contains invariants.
- ccv_test.qnt: Contains unit tests for the functional layer of CCV.
- libraries/*: Libraries that don't belong to CCV, but are used by it.

### Model details

To see the data structures used in the model, see the `ProtocolState` type in ccv.qnt.

The "public" endpoints of the model are those functions that take as an input the protocol state, and return a `Result`.
Other functions are for utility.

The parameters of the protocol are defined as consts in [ccv.qnt](ccv.qnt).

### Tests

To run unit tests, run
```
quint test ccv_test.qnt
```
and
```
quint test ccv_statemachine.qnt
```

### Invariants

The invariants to check are in [ccv_statemachine.qnt](ccv_statemachine.qnt).
Check a single invariant by running
`quint run --invariant INVARIANT_NAME ccv_statemachine.qnt`,
or all invariants one after another with the help of the script `run_invariants.sh`.
Each invariant takes about a minute to run.

Invariants are as follows:
- [X] ValidatorUpdatesArePropagatedInv: When a validator power update is comitted on chain, a packet containing that change in voting power is sent to all running consumers.
- [X] ValidatorSetHasExistedInv: Every validator set on consumer chains is/was a validator set on the provider.
- [X] SameVscPacketsInv: Ensure that consumer chains receive the same VscPackets in the same order.
Because of nuances with starting/stopping consumers, this invariant is not as simple as it sounds. In detail:
For consumer chains c1, c2, if both c1 and c2 received a packet p1 sent at t1 and a packet p2 sent at t2,
then both have received ALL packets that were sent between t1 and t2 in the same order.
- [X] MatureOnTimeInv: For every ValidatorSetChangePacket received by a consumer chain at
time t, a MaturedVscPacket is sent back to the provider in the first block
with a timestamp >= t + UnbondingPeriod on that consumer.
- [X] EventuallyMatureOnProviderInv: If we send a VscPacket, this is eventually responded to by all consumers
that were running at the time the packet was sent (and are still running).

Invariants can also be model-checked by Apalache, using this command:
```
quint verify --invariant ValidatorUpdatesArePropagatedInv,ValidatorSetHasExistedInv,SameVscPacketsInv,MatureOnTimeInv,EventuallyMatureOnProviderInv \
ccv_statemachine.qnt
```

### Sanity Checks

Sanity checks verify that certain patterns of behaviour can appear in the model.
In detail, they are invariant checks that we expect to fail.
They usually negate the appearance of some behaviour, i.e. `not(DesirableBehaviour)`.
Then, a counterexample for this is an example trace exhibiting the behaviour.

They are run like invariant checks, i.e. `quint run --invariant SANITY_CHECK_NAME ccv_statemachine.qnt`.
The available sanity checks are:
- CanRunConsumer
- CanStopConsumer
- CanTimeoutConsumer
- CanSendVscPackets
- CanSendVscMaturedPackets
Loading
Loading