Skip to content

Commit

Permalink
Add Echidna fuzzing with CI support (#8)
Browse files Browse the repository at this point in the history
* echidna config

* echidna-action

* echidna vault with seeding

* better abstraction for invariants

* move to echidna folder

* corpus caching + coverage upload as artifact

* limit test to 30000 a pop
  • Loading branch information
coolhill authored Mar 2, 2022
1 parent f60dd0c commit 1fa648d
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 0 deletions.
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);
}

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.

0 comments on commit 1fa648d

Please sign in to comment.