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 Echidna fuzzing with CI support #8

Merged
merged 15 commits into from
Mar 2, 2022
50 changes: 50 additions & 0 deletions .github/workflows/echidna.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Echidna Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
test:
- Echidna_Deposit_Withdraw

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16'
cache: 'yarn'
- uses: actions/setup-python@v2
with:
python-version: '3.x'

- run: yarn install
- run: yarn run hardhat compile

- name: Cache ${{ matrix.test }} corpus
uses: actions/cache@v2
with:
path: corpus
key: abi-${{ matrix.test }}-v2

- name: Run Echidna
uses: crytic/echidna-action@v1
with:
solc-version: 0.8.10
files: .
contract: ${{ matrix.test }}
crytic-args: --hardhat-ignore-compile
config: contracts/echidna/${{ matrix.test }}.yml

- name: Upload ${{ matrix.test }} coverage
uses: actions/upload-artifact@v2
with:
name: coverage-${{ matrix.test }}
path: corpus/covered.*
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ deployments/hardhat
deployments/docker
subgraph/generated
subgraph/tests/.bin/*
crytic-export/
corpus/
10 changes: 10 additions & 0 deletions contracts/echidna/Addresses.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.10;

import "../Vault.sol";
import "../test/TestERC20.sol";

contract Addresses {
Vault vault = Vault(0x6A4A62E5A7eD13c361b176A5F62C2eE620Ac0DF8);
TestERC20 underlying = TestERC20(0x1dC4c1cEFEF38a777b15aA20260a54E584b16C48);
}
19 changes: 19 additions & 0 deletions contracts/echidna/Echidna_Deposit_Withdraw.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.10;
import "./Helper.sol";

contract Echidna_Deposit_Withdraw is Helper {

// zero address should always revert
function withdraw_zero_address_recipient(uint256[] memory _ids) public {
withdraw_should_revert(address(0), _ids);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ reviewer, this is the one invariant added for now, stating that a withdraw should always revert if recipient is 0x0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more interesting ones will be added in another PR


function withdraw_should_revert(address recipient, uint256[] memory _ids) internal {
try vault.withdraw(recipient, _ids) {
assert(false);
} catch {
assert(true);
}
}
}
6 changes: 6 additions & 0 deletions contracts/echidna/Echidna_Deposit_Withdraw.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
initialize: contracts/echidna/init.json
coverage: true
testMode: assertion
testLimit: 30000
corpusDir: 'corpus'
codeSize: 0xfffffffffff
8 changes: 8 additions & 0 deletions contracts/echidna/Helper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.10;
import "./Addresses.sol";

contract Helper is Addresses {


}
25 changes: 25 additions & 0 deletions contracts/echidna/init.json

Large diffs are not rendered by default.