forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: halmos symbolic tests #21
Merged
0xteddybear
merged 64 commits into
feat/invariant-testing
from
feat/halmos-symbolic-tests
Aug 23, 2024
Merged
Changes from all commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
4394925
feat: introduce OptimismSuperchainERC20
agusduha bb247fa
fix: contract fixes
agusduha feea60d
feat: add snapshots and semver
agusduha c23e226
test: add supports interface tests
agusduha 61d10d9
test: add invariant test
agusduha d1d2f28
feat: add parameters to the RelayERC20 event
agusduha 7dd28e1
fix: typo
agusduha 68bcdca
fix: from param description
agusduha ca487dc
fix: event signature and interface pragma
0xng 475d83d
feat: add initializer
agusduha a7fdcf6
feat: use unstructured storage and OZ v5
agusduha 392c49a
Merge branch 'develop' into sc/superchain-erc20
agusduha 1ed5895
feat: update superchain erc20 interfaces
agusduha 8de4f01
fix: adapt storage to ERC7201
agusduha d167dce
test: add initializable OZ v5 test
agusduha 176d232
Merge branch 'develop' into sc/superchain-erc20
agusduha e0e5910
fix: invariant docs
agusduha 5514694
fix: ERC165 implementation
agusduha b3813f8
Merge branch 'develop' into sc/superchain-erc20
agusduha eac9884
test: improve superc20 invariant (#11)
0xDiscotech 97e08de
Merge branch 'develop' into sc/superchain-erc20
agusduha 97377fe
fix: gas snapshot
agusduha f6c3f90
chore: configure medusa with basic supERC20 self-bridging
0xteddybear fcbf7fe
fix: delete dead code
0xteddybear 473a0bb
test: give the fuzzer a head start
0xteddybear c8ccdc7
feat: create suite for sybolic tests with halmos
0xDiscotech 5f125fa
chore: remove todo comment
0xDiscotech ca1f668
docs: fix properties order
0xteddybear 8331006
test: document & implement assertions 22, 23 and 24
0xteddybear 466c605
fix: fixes from self-review
0xteddybear d8ad2b1
test: guide the fuzzer a little bit less
0xteddybear 1a0c46e
feat: add property for burn
0xDiscotech 91d378e
feat: checkpoint
0xDiscotech 7157066
chore: set xdomain sender on failing test
0xDiscotech 5dcb3a8
chore: enhance mocks
0xDiscotech 945d6b6
Merge branch 'chore/setup-medusa' into feat/halmos-symbolic-tests
0xDiscotech 15c04d5
Revert "Merge branch 'chore/setup-medusa' into feat/halmos-symbolic-t…
0xDiscotech 13fc70a
refactor: remove symbolic addresses to make all of the test work
0xDiscotech 4a99ffd
chore: remove console logs
0xDiscotech 741971a
feat: add properties file
0xDiscotech 066a22f
refactor: enhance test on property 7 using direct try catch (now works)
0xDiscotech 2640556
fix: review comments
0xDiscotech 3b831a6
refactor: add symbolic addresses on test functions
0xDiscotech b65259c
chore: update property
0xDiscotech 22d15bf
Merge branch 'chore/setup-medusa' into feat/halmos-symbolic-tests
0xDiscotech bc49b4e
refactor: move symbolic folder into properties one
0xDiscotech cc66e13
refactor: enhance tests using symbolic addresses instead of concrete …
0xDiscotech 0032eb6
chore: remove 0 property natspec
0xDiscotech cb36b0c
feat: add halmos profile and just script
0xDiscotech a982ccb
feat: add halmos commands to justfile
0xDiscotech a83b29e
chore: reorder assertions on one test
0xDiscotech be57ac8
refactor: complete test property seven
0xDiscotech 787c2d7
chore: mark properties as completed
0xDiscotech 313429f
Merge branch 'chore/setup-medusa' into feat/halmos-symbolic-tests
0xDiscotech 98557e0
chore: add halmos-cheatcodes dependency
0xteddybear 4945501
chore: rename advancedtest->halmosbase
0xteddybear 0fcf844
chore: minimize mocked messenger
0xteddybear a974787
chore: delete empty halmos file
0xteddybear 4ec3c30
chore: revert changes to medusa.json
0xteddybear bf49cdf
docs: update changes to PROPERTIES.md from base branch
0xteddybear 50a8577
test: sendERC20 destination fix
0xteddybear 2928e5a
chore: natspec fixes
0xteddybear 99b26fa
Merge pull request #32 from defi-wonderland/chore/feedback-on-halmos-…
0xteddybear 542b539
chore: merge base branch & fix conflicts
0xteddybear 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
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,15 @@ | ||
# Halmos configuration file | ||
|
||
## The version needed is `halmos 0.1.15.dev2+gc3f45dd` | ||
## Just running `halmos` will run the tests with the default configuration | ||
|
||
[global] | ||
# Contract to test | ||
match-contract = "SymTest_" | ||
|
||
# Path to the Forge artifacts directory | ||
forge_build_out = "./forge-artifacts" | ||
|
||
|
||
# Storage layout | ||
storage_layout = "generic" |
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
Submodule halmos-cheatcodes
added at
c0d865
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,73 @@ | ||
# supertoken properties | ||
|
||
legend: | ||
|
||
- `[ ]`: property not yet tested | ||
- `**[ ]**`: property not yet tested, dev/research team has asked for extra focus on it | ||
- `[X]`: tested/proven property | ||
- `[~]`: partially tested/proven property | ||
- `:(`: property won't be tested due to some limitation | ||
|
||
## Unit test | ||
|
||
| id | description | halmos | medusa | | ||
| --- | ---------------------------------------------------------------------------------- | ------ | ------ | | ||
| 0 | supertoken token address does not depend on the executing chain’s chainID | [ ] | [ ] | | ||
| 1 | supertoken token address depends on name, remote token, address and decimals | [ ] | [ ] | | ||
| 2 | convert() should only allow converting legacy tokens to supertoken and viceversa | [ ] | [ ] | | ||
| 3 | convert() only allows migrations between tokens representing the same remote asset | [ ] | [ ] | | ||
| 4 | convert() only allows migrations from tokens with the same decimals | [ ] | [ ] | | ||
| 5 | convert() burns the same amount of one token that it mints of the other | [ ] | [ ] | | ||
|
||
## Valid state | ||
|
||
| id | description | halmos | medusa | | ||
| --- | ------------------------------------------------------------------------------------------ | ------- | ------ | | ||
| 6 | calls to sendERC20 succeed as long as caller has enough balance | [x] | [ ] | | ||
| 7 | calls to relayERC20 always succeed as long as the sender and cross-domain caller are valid | **[~]** | [ ] | | ||
|
||
## Variable transition | ||
|
||
| id | description | halmos | medusa | | ||
| --- | ------------------------------------------------------------------------------------------------- | ------ | ------ | | ||
| 8 | sendERC20 with a value of zero does not modify accounting | [x] | [ ] | | ||
| 9 | relayERC20 with a value of zero does not modify accounting | [x] | [ ] | | ||
| 10 | sendERC20 decreases the token's totalSupply in the source chain exactly by the input amount | [x] | [ ] | | ||
| 11 | relayERC20 increases the token's totalSupply in the destination chain exactly by the input amount | [x] | [ ] | | ||
| 12 | supertoken total supply only increases on calls to mint() by the L2toL2StandardBridge | [x] | [ ] | | ||
| 13 | supertoken total supply only decreases on calls to burn() by the L2toL2StandardBridge | [x] | [ ] | | ||
| 14 | supertoken total supply starts at zero | [x] | [ ] | | ||
| 15 | deploying a supertoken registers its remote token in the factory | [ ] | [ ] | | ||
| 16 | deploying an OptimismMintableERC20 registers its remote token in the factory | [ ] | [ ] | | ||
|
||
## High level | ||
|
||
| id | description | halmos | medusa | | ||
| --- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ | | ||
| 17 | only calls to convert(legacy, super) can increase a supertoken’s total supply across chains | [ ] | [ ] | | ||
| 18 | only calls to convert(super, legacy) can decrease a supertoken’s total supply across chains | [ ] | [ ] | | ||
| 19 | sum of total supply across all chains is always <= to convert(legacy, super)- convert(super, legacy) | [ ] | [ ] | | ||
| 20 | tokens sendERC20-ed on a source chain to a destination chain can be relayERC20-ed on it as long as the source chain is in the dependency set of the destination chain | [ ] | [ ] | | ||
| 21 | sum of supertoken total supply across all chains is = to convert(legacy, super)- convert(super, legacy) when all cross-chain messages are processed | [ ] | [ ] | | ||
|
||
## Atomic bridging pseudo-properties | ||
|
||
As another layer of defense, the following properties are defined which assume bridging operations to be atomic (that is, the sequencer and L2Inbox and CrossDomainMessenger contracts are fully abstracted away, `sendERC20` triggering the `relayERC20` call on the same transaction) | ||
It’s worth noting that these properties will not hold for a live system | ||
|
||
| id | description | halmos | medusa | | ||
| --- | ---------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ | | ||
| 22 | sendERC20 decreases sender balance in source chain and increases receiver balance in destination chain exactly by the input amount | [ ] | [x] | | ||
| 23 | sendERC20 decreases total supply in source chain and increases it in destination chain exactly by the input amount | [ ] | [x] | | ||
| 24 | sum of supertoken total supply across all chains is always equal to convert(legacy, super)- convert(super, legacy) | [ ] | [~] | | ||
|
||
# Expected external interactions | ||
|
||
- regular ERC20 operations between any accounts on the same chain, provided by [crytic ERC20 properties](https://github.com/crytic/properties?tab=readme-ov-file#erc20-tests) | ||
|
||
# Invariant-breaking candidates (brain dump) | ||
|
||
here we’ll list possible interactions that we intend the fuzzing campaign to support in order to help break invariants | ||
|
||
- [ ] changing the decimals of tokens after deployment | ||
- [ ] `convert()` ing between multiple (3+) representations of the same remote token, by having different names/symbols |
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
25 changes: 25 additions & 0 deletions
25
packages/contracts-bedrock/test/properties/halmos/MockL2ToL2Messenger.sol
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I managed to get the contract down to this:
with all tests passing. I believe the extra code makes it a bit confusing for the reader |
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,25 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
|
||
// TODO: Try to merge to a single mocked contract used by fuzzing and symbolic invariant tests - only if possible | ||
// and low priorty | ||
contract MockL2ToL2Messenger { | ||
// Setting the current cross domain sender for the check of sender address equals the supertoken address | ||
address internal immutable CROSS_DOMAIN_SENDER; | ||
|
||
constructor(address _xDomainSender) { | ||
CROSS_DOMAIN_SENDER = _xDomainSender; | ||
} | ||
|
||
function sendMessage(uint256 , address , bytes calldata) external payable { | ||
} | ||
|
||
function crossDomainMessageSource() external view returns (uint256 _source) { | ||
_source = block.chainid + 1; | ||
} | ||
|
||
function crossDomainMessageSender() external view returns (address _sender) { | ||
_sender = CROSS_DOMAIN_SENDER; | ||
} | ||
} |
Oops, something went wrong.
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.
✨