secureum-medusa
secureum-medusa copied to clipboard
Secureum Medusa workshop
The goals of this workshop are to:
- Learn about invariants development
- Become familar with the medusa fuzzer
Medusa is a new experimental fuzzer. Do not hesitate to ask questions on secureum's discord, or create github issues if you encounter any issue.
Before starting
To install medusa, follow the installation instructions.
Solc
Solc 0.8.19 is used for this workshop. We recommend solc-select to easily switch between solc versions:
pip3 install solc-select
solc-select install 0.8.19
solc-select use 0.8.19
The contest
The goals of the contest is to write invariants for three targets (SignedWadMath, FixedPointMathLib, ERC20Burn). All the contracts are inspired from solmate.
Helper
helpercomes from the properties repo, and contains helpers to ease the creation of invariants. In particular we recommend to use:asssertX(Eq,Neq,Gte,Gt,Lte,Lt) to test assertion between valuesclampX(Between,Lt,Lte,Gt,Gte) to restraint the inputs' values
SignedWadMath
SignedWadMathis a signed 18 decimal fixed point (wad) arithmetic library.SignedWadMathTestis an example of test forSignedWadMathtesttoWadUnsafeis an example of invariant to help you
FixedPointMathLib
FixedPointMathLibis an arithmetic library with operations for fixed-point numbers.FixedPointMathLibTestis an example of test forSignedWadMathtestmulDivDownis an example of invariant to help you
ERC20Burn
ERC20is a standard ERC20 token.ERC20BurnextendsERC20with a burn functionERC20Testis an example of test forERC20Burnfuzz_Supplyis an example of invariant to help you
ERC20TestAdvancedis an example of an advanced test forERC20BurnERC20TestAdvanceduses the external testing approach and uses a proxy contract to simulate a user. This approach is more complex to use, but allows to test for more complex scenariotestTransferFromis an example of invariant to help you
ERC20Burn
How to start
A few pointers to start:
- Read the documentation
- Start small, and create simple invariants first
- Start with
SignedWadMath
- Start with
- Consider when operation should or it should not revert
- Some properties could require to use certain tolerance
ERC20TestAdvancedis recommended only for users that have already explored the other contracts- Do not hesitate to introduce bugs in your code to verify that your invariants can catch them
To start a fuzzing campagn
medusa fuzz --target contracts/NAME.sol --deployment-order CONTRACT_NAME
Replace NAME.sol and CONTRACT_NAME.
Expected Results and Evaluation
User should be able to fully test the contracts. It is worth mentioning that the code is unmodified and there are no known issues. If you find some security or correctness issue in the code do NOT post it in this repository nor upstream, since these are public messages. Instead, contact us to confirm the issue and discuss how to proceed.
For Secureum, the resulting properties will be evaluated introducing an artificial bug in the code and running a short fuzzing campaign.
We encourage you to try different approaches and invariants. Invariants based development is a powerful tool for developer and auditors that require practices and experience to master it.
Configuration
medusa.json was generated with medusa init. The following changes were applied:
testAllContractswas set to truecorpusDirectorywas set to "corpus"assertionTesting/enabledwas set to true
Documentation
Self-Evaluation
See Evaluation