From b8b0c4694a607d5d3853a146891f31eef3f834e9 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Fri, 30 Apr 2021 22:40:49 +0100 Subject: [PATCH 01/45] Add echidna tests for dss-vest --- src/fuzz/DssVestEchidnaTest.sol | 82 +++++++++++++++++++++++++++++++++ src/fuzz/echidna.config.yml | 12 +++++ 2 files changed, 94 insertions(+) create mode 100644 src/fuzz/DssVestEchidnaTest.sol create mode 100644 src/fuzz/echidna.config.yml diff --git a/src/fuzz/DssVestEchidnaTest.sol b/src/fuzz/DssVestEchidnaTest.sol new file mode 100644 index 00000000..d15732c6 --- /dev/null +++ b/src/fuzz/DssVestEchidnaTest.sol @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +pragma solidity 0.6.12; + +import "../DssVest.sol"; + +contract DssVestEchidnaTest { + + DssVest internal vest; + IMKR internal MKR; + + constructor() public { + vest = new DssVest(address(MKR)); + } + + // --- Math --- + + uint256 internal constant WAD = 10**18; + + function add(uint256 x, uint256 y) internal pure returns (uint256 z) { + require((z = x + y) >= x); + } + function sub(uint256 x, uint256 y) internal pure returns (uint256 z) { + require((z = x - y) <= x); + } + + function test_init_ids(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr) public { + _amt = 1 * WAD + _amt % uint128(-1); + _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); + _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); + _clf = 1 + _clf % _tau; + _pmt = 1 * WAD + _pmt % _amt; + uint256 prevId = vest.ids(); + uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); + assert(vest.ids() == add(prevId, id)); + assert(vest.valid(id)); + } + + function test_init_params(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr) public { + _amt = 1 * WAD + _amt % uint128(-1); + _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); + _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); + _clf = 1 + _clf % _tau; + _pmt = 1 * WAD + _pmt % _amt; + uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); + (address usr, uint48 bgn, uint48 clf, uint48 fin, uint128 amt, uint128 rxd, address mgr) = vest.awards(id); + if (sub(_amt, _pmt) != 0) { + assert(usr == (address(this))); + assert(bgn == uint48(_bgn)); + assert(clf == add(_bgn, _clf)); + assert(fin == add(_bgn, _tau)); + assert(amt == sub(_amt, _pmt)); + assert(rxd == uint128(0)); + assert(mgr == _mgr); + } + } + + function test_vest(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr, uint256 _tick) public { + _amt = 1 * WAD + _amt % uint128(-1); + _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); + _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); + _clf = 1 + _clf % _tau; + _pmt = 1 * WAD + _pmt % _amt; + _tick = block.timestamp + _tick % uint128(-1); + uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); + assert(vest.valid(id)); + uint256 ids = vest.ids(); + vest.vest(id); + (address usr, uint48 bgn, uint48 clf, uint48 fin, uint128 amt, uint128 rxd, address mgr) = vest.awards(id); + if (_tick < fin) { + assert (vest.ids() == sub(ids, 1)); + } else if (_tick >= clf) { + uint256 t = (_tick - bgn) * WAD / (fin - bgn); + assert(t >= 0); + assert(t < WAD); + uint256 mkr = (amt * t) / WAD; + assert(mkr >= 0); + assert(mkr < amt); + assert(rxd == uint128(mkr)); + } + } +} diff --git a/src/fuzz/echidna.config.yml b/src/fuzz/echidna.config.yml new file mode 100644 index 00000000..c463ebf1 --- /dev/null +++ b/src/fuzz/echidna.config.yml @@ -0,0 +1,12 @@ +#format can be "text" or "json" for different output (human or machine readable) +#format: "text" +#checkAsserts checks assertions +checkAsserts: true +#coverage controls coverage guided testing +coverage: false +#seqLen defines how many transactions are in a test sequence +seqLen: 50 +#testLimit is the number of test sequences to run +testLimit: 100000 +#estimateGas makes echidna perform analysis of maximum gas costs for functions (experimental) +#estimateGas: true From 76263a240a1244701361d0fc39e24c6a4ad40a7c Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Mon, 3 May 2021 14:21:20 +0100 Subject: [PATCH 02/45] Add fuzz docs to readme --- README.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..dfacf9d7 --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +# dss-vest + +## Fuzz + +### Install Echidna + +- Building using Nix + `$ nix-env -i -f https://github.com/crytic/echidna/tarball/master` + +- Building using Docker + `$ docker build -t echidna .` + +Then, run via: +`docker run -it -v`pwd`:/src echidna echidna-test /src/fuzz/DssVestEchidnaTest.sol` + +- Precompiled Binaries + +Before starting, make sure Slither is installed: +`$ pip3 install slither-analyzer` + +To quickly test Echidna in Linux or MacOS: +[release page](https://github.com/crytic/echidna/releases) + +### Local Dependencies + +- Slither + `$ pip3 install slither-analyzer` + +- solc-select + `$ pip3 install solc-select` + +### Run Echidna Tests + +- Install solc version: + `$ solc-select install 0.6.12` + +- Select solc version: + `$ solc-select use 0.6.12` + +- Run Echidna Tests: + `$ echidna-test src/fuzz/DssVestEchidnaTest.sol --contract DssVestEchidnaTest --config src/fuzz/echidna.config.yml` From 249bc1099a381170b370185b37d75cedd7c00ca7 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Mon, 3 May 2021 14:28:57 +0100 Subject: [PATCH 03/45] Add fuzz CI + update echidna config + cleanup --- .github/workflows/fuzz.yml | 51 +++++++++++++++++++ .../echidna.config.yml => echidna.config.yml | 6 +-- 2 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/fuzz.yml rename src/fuzz/echidna.config.yml => echidna.config.yml (90%) diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml new file mode 100644 index 00000000..8ea754e5 --- /dev/null +++ b/.github/workflows/fuzz.yml @@ -0,0 +1,51 @@ +name: Fuzz + +on: + push: + branches: + - master + pull_request: + +jobs: + echidna: + name: Echidna + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + testName: + - DssVestEchidnaTest + + steps: + - uses: actions/checkout@v2 + + - name: Set up node + uses: actions/setup-node@v2 + with: + node-version: 12 + + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Install pip3 + run: | + python -m pip install --upgrade pip + - name: Install slither + run: | + pip3 install slither-analyzer + - name: Install solc-select + run: | + pip3 install solc-select + - name: Set solc v0.6.12 + run: | + solc-select install 0.6.12 + solc-select use 0.6.12 + - name: Install echidna + run: | + sudo wget -O /tmp/echidna-test.tar.gz https://github.com/crytic/echidna/releases/download/v1.6.0/echidna-test-v1.6.0-Ubuntu-18.04.tar.gz + sudo tar -xf /tmp/echidna-test.tar.gz -C /usr/bin + sudo chmod +x /usr/bin/echidna-test + - name: Run ${{ matrix.testName }} + run: echidna-test src/fuzz/DssVestEchidnaTest.sol --contract ${{ matrix.testName }} --config echidna.config.yml diff --git a/src/fuzz/echidna.config.yml b/echidna.config.yml similarity index 90% rename from src/fuzz/echidna.config.yml rename to echidna.config.yml index c463ebf1..07aec427 100644 --- a/src/fuzz/echidna.config.yml +++ b/echidna.config.yml @@ -1,12 +1,12 @@ #format can be "text" or "json" for different output (human or machine readable) -#format: "text" +format: "text" #checkAsserts checks assertions checkAsserts: true #coverage controls coverage guided testing coverage: false #seqLen defines how many transactions are in a test sequence -seqLen: 50 +#seqLen: 50 #testLimit is the number of test sequences to run -testLimit: 100000 +#testLimit: 100000 #estimateGas makes echidna perform analysis of maximum gas costs for functions (experimental) #estimateGas: true From ce48f5affb7632c7f03f683c4296495785bd9b44 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Mon, 3 May 2021 14:34:02 +0100 Subject: [PATCH 04/45] Add CI fuzz badge + local fuzz settings to readme --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index dfacf9d7..3773c2c4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Fuzz](https://github.com/brianmcmichael/dss-vest/actions/workflows/fuzz.yml/badge.svg)](https://github.com/brianmcmichael/dss-vest/actions/workflows/fuzz.yml) + # dss-vest ## Fuzz @@ -29,6 +31,15 @@ To quickly test Echidna in Linux or MacOS: - solc-select `$ pip3 install solc-select` +### Local Fuzz Settings + +- Edit `echidna.config.yml` +- Comment `format: "text"` +- Set `coverage` to true +- Uncomment `seqLen` +- Uncomment `testLimit` +- Uncomment `estimateGas` (optional) + ### Run Echidna Tests - Install solc version: From 9b5ac4884622ba570486240d1fc9c505381ae822 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Mon, 3 May 2021 14:53:38 +0100 Subject: [PATCH 05/45] Cleanup readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3773c2c4..d68b95a3 100644 --- a/README.md +++ b/README.md @@ -49,4 +49,4 @@ To quickly test Echidna in Linux or MacOS: `$ solc-select use 0.6.12` - Run Echidna Tests: - `$ echidna-test src/fuzz/DssVestEchidnaTest.sol --contract DssVestEchidnaTest --config src/fuzz/echidna.config.yml` + `$ echidna-test src/fuzz/DssVestEchidnaTest.sol --contract DssVestEchidnaTest --config echidna.config.yml` From ccdc6adc49115cc76096c5fb7321b1f096e52929 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Mon, 3 May 2021 19:00:56 +0100 Subject: [PATCH 06/45] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e2e7327c..320ed03a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /out +crytic-export/ From c758324aadb1b43a784955396c81377fef7f9054 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Mon, 3 May 2021 19:11:55 +0100 Subject: [PATCH 07/45] Update readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index d68b95a3..1a180ac4 100644 --- a/README.md +++ b/README.md @@ -48,5 +48,8 @@ To quickly test Echidna in Linux or MacOS: - Select solc version: `$ solc-select use 0.6.12` +- If using Dapp Tools: + `$ nix-env -f https://github.com/dapphub/dapptools/archive/master.tar.gz -iA solc-versions.solc_0_6_12` + - Run Echidna Tests: `$ echidna-test src/fuzz/DssVestEchidnaTest.sol --contract DssVestEchidnaTest --config echidna.config.yml` From 859bd830773079ff932ccee75d2d76557eba939b Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 5 May 2021 13:23:30 +0100 Subject: [PATCH 08/45] Allow _clf equal zero --- src/fuzz/DssVestEchidnaTest.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fuzz/DssVestEchidnaTest.sol b/src/fuzz/DssVestEchidnaTest.sol index d15732c6..55d0a3e8 100644 --- a/src/fuzz/DssVestEchidnaTest.sol +++ b/src/fuzz/DssVestEchidnaTest.sol @@ -28,7 +28,7 @@ contract DssVestEchidnaTest { _amt = 1 * WAD + _amt % uint128(-1); _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); - _clf = 1 + _clf % _tau; + _clf = 0 + _clf % _tau; _pmt = 1 * WAD + _pmt % _amt; uint256 prevId = vest.ids(); uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); @@ -40,7 +40,7 @@ contract DssVestEchidnaTest { _amt = 1 * WAD + _amt % uint128(-1); _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); - _clf = 1 + _clf % _tau; + _clf = 0 + _clf % _tau; _pmt = 1 * WAD + _pmt % _amt; uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); (address usr, uint48 bgn, uint48 clf, uint48 fin, uint128 amt, uint128 rxd, address mgr) = vest.awards(id); @@ -59,7 +59,7 @@ contract DssVestEchidnaTest { _amt = 1 * WAD + _amt % uint128(-1); _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); - _clf = 1 + _clf % _tau; + _clf = 0 + _clf % _tau; _pmt = 1 * WAD + _pmt % _amt; _tick = block.timestamp + _tick % uint128(-1); uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); From a7067de2e19fa02e3db329d60497c659d8dcbac3 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 5 May 2021 14:26:09 +0100 Subject: [PATCH 09/45] Set _amt and _pmt min seed value to zero --- src/fuzz/DssVestEchidnaTest.sol | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/fuzz/DssVestEchidnaTest.sol b/src/fuzz/DssVestEchidnaTest.sol index 55d0a3e8..4b1aee1c 100644 --- a/src/fuzz/DssVestEchidnaTest.sol +++ b/src/fuzz/DssVestEchidnaTest.sol @@ -25,11 +25,11 @@ contract DssVestEchidnaTest { } function test_init_ids(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr) public { - _amt = 1 * WAD + _amt % uint128(-1); + _amt = 0 + _amt % uint128(-1); _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); _clf = 0 + _clf % _tau; - _pmt = 1 * WAD + _pmt % _amt; + _pmt = 0 + _pmt % _amt; uint256 prevId = vest.ids(); uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); assert(vest.ids() == add(prevId, id)); @@ -37,11 +37,11 @@ contract DssVestEchidnaTest { } function test_init_params(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr) public { - _amt = 1 * WAD + _amt % uint128(-1); + _amt = 0 + _amt % uint128(-1); _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); _clf = 0 + _clf % _tau; - _pmt = 1 * WAD + _pmt % _amt; + _pmt = 0 + _pmt % _amt; uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); (address usr, uint48 bgn, uint48 clf, uint48 fin, uint128 amt, uint128 rxd, address mgr) = vest.awards(id); if (sub(_amt, _pmt) != 0) { @@ -56,11 +56,11 @@ contract DssVestEchidnaTest { } function test_vest(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr, uint256 _tick) public { - _amt = 1 * WAD + _amt % uint128(-1); + _amt = 0 + _amt % uint128(-1); _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); _clf = 0 + _clf % _tau; - _pmt = 1 * WAD + _pmt % _amt; + _pmt = 0 + _pmt % _amt; _tick = block.timestamp + _tick % uint128(-1); uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); assert(vest.valid(id)); From 15b99cd1d9b8d888f5e9d5141abc09bb5579dd6d Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 5 May 2021 20:40:12 +0100 Subject: [PATCH 10/45] Fix _amt seed value with check for WAD --- src/fuzz/DssVestEchidnaTest.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fuzz/DssVestEchidnaTest.sol b/src/fuzz/DssVestEchidnaTest.sol index 4b1aee1c..0c59d67b 100644 --- a/src/fuzz/DssVestEchidnaTest.sol +++ b/src/fuzz/DssVestEchidnaTest.sol @@ -25,7 +25,7 @@ contract DssVestEchidnaTest { } function test_init_ids(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr) public { - _amt = 0 + _amt % uint128(-1); + _amt = _amt < WAD ? _amt *= WAD : _amt % uint128(-1); _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); _clf = 0 + _clf % _tau; @@ -37,7 +37,7 @@ contract DssVestEchidnaTest { } function test_init_params(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr) public { - _amt = 0 + _amt % uint128(-1); + _amt = _amt < WAD ? _amt *= WAD : _amt % uint128(-1); _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); _clf = 0 + _clf % _tau; @@ -56,7 +56,7 @@ contract DssVestEchidnaTest { } function test_vest(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr, uint256 _tick) public { - _amt = 0 + _amt % uint128(-1); + _amt = _amt < WAD ? _amt *= WAD : _amt % uint128(-1); _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); _clf = 0 + _clf % _tau; From a2a1c3f17d514fe2fdddd2debf3f184d40dfe61d Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 5 May 2021 21:10:49 +0100 Subject: [PATCH 11/45] Remove _tick + fix fin check + cleanup --- src/fuzz/DssVestEchidnaTest.sol | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/fuzz/DssVestEchidnaTest.sol b/src/fuzz/DssVestEchidnaTest.sol index 0c59d67b..e6e6a3d3 100644 --- a/src/fuzz/DssVestEchidnaTest.sol +++ b/src/fuzz/DssVestEchidnaTest.sol @@ -25,7 +25,7 @@ contract DssVestEchidnaTest { } function test_init_ids(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr) public { - _amt = _amt < WAD ? _amt *= WAD : _amt % uint128(-1); + _amt = _amt < WAD ? _amt *= WAD : _amt % uint128(-1); _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); _clf = 0 + _clf % _tau; @@ -37,7 +37,7 @@ contract DssVestEchidnaTest { } function test_init_params(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr) public { - _amt = _amt < WAD ? _amt *= WAD : _amt % uint128(-1); + _amt = _amt < WAD ? _amt *= WAD : _amt % uint128(-1); _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); _clf = 0 + _clf % _tau; @@ -55,22 +55,21 @@ contract DssVestEchidnaTest { } } - function test_vest(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr, uint256 _tick) public { - _amt = _amt < WAD ? _amt *= WAD : _amt % uint128(-1); + function test_vest(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr) public { + _amt = _amt < WAD ? _amt *= WAD : _amt % uint128(-1); _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); _clf = 0 + _clf % _tau; _pmt = 0 + _pmt % _amt; - _tick = block.timestamp + _tick % uint128(-1); uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); assert(vest.valid(id)); uint256 ids = vest.ids(); vest.vest(id); (address usr, uint48 bgn, uint48 clf, uint48 fin, uint128 amt, uint128 rxd, address mgr) = vest.awards(id); - if (_tick < fin) { + if (block.timestamp >= fin) { assert (vest.ids() == sub(ids, 1)); - } else if (_tick >= clf) { - uint256 t = (_tick - bgn) * WAD / (fin - bgn); + } else if (block.timestamp >= clf) { + uint256 t = (block.timestamp - bgn) * WAD / (fin - bgn); assert(t >= 0); assert(t < WAD); uint256 mkr = (amt * t) / WAD; From 987d9e9f9c5364735bdd3e1fff15cf070b1530db Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 5 May 2021 21:26:21 +0100 Subject: [PATCH 12/45] Cleanup --- src/fuzz/DssVestEchidnaTest.sol | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/fuzz/DssVestEchidnaTest.sol b/src/fuzz/DssVestEchidnaTest.sol index e6e6a3d3..c72b0e1e 100644 --- a/src/fuzz/DssVestEchidnaTest.sol +++ b/src/fuzz/DssVestEchidnaTest.sol @@ -28,8 +28,8 @@ contract DssVestEchidnaTest { _amt = _amt < WAD ? _amt *= WAD : _amt % uint128(-1); _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); - _clf = 0 + _clf % _tau; - _pmt = 0 + _pmt % _amt; + _clf = _clf % _tau; + _pmt = _pmt % _amt; uint256 prevId = vest.ids(); uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); assert(vest.ids() == add(prevId, id)); @@ -40,8 +40,8 @@ contract DssVestEchidnaTest { _amt = _amt < WAD ? _amt *= WAD : _amt % uint128(-1); _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); - _clf = 0 + _clf % _tau; - _pmt = 0 + _pmt % _amt; + _clf = _clf % _tau; + _pmt = _pmt % _amt; uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); (address usr, uint48 bgn, uint48 clf, uint48 fin, uint128 amt, uint128 rxd, address mgr) = vest.awards(id); if (sub(_amt, _pmt) != 0) { @@ -59,8 +59,8 @@ contract DssVestEchidnaTest { _amt = _amt < WAD ? _amt *= WAD : _amt % uint128(-1); _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); - _clf = 0 + _clf % _tau; - _pmt = 0 + _pmt % _amt; + _clf = _clf % _tau; + _pmt = _pmt % _amt; uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); assert(vest.valid(id)); uint256 ids = vest.ids(); From 8bd10a3a34312ce35ae3bd7fe4f46bd7572e5c88 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Thu, 6 May 2021 00:05:49 +0100 Subject: [PATCH 13/45] Fix _amt seed + assert ids --- src/fuzz/DssVestEchidnaTest.sol | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/fuzz/DssVestEchidnaTest.sol b/src/fuzz/DssVestEchidnaTest.sol index c72b0e1e..b9665910 100644 --- a/src/fuzz/DssVestEchidnaTest.sol +++ b/src/fuzz/DssVestEchidnaTest.sol @@ -25,19 +25,22 @@ contract DssVestEchidnaTest { } function test_init_ids(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr) public { - _amt = _amt < WAD ? _amt *= WAD : _amt % uint128(-1); + _amt = _amt % uint128(-1); + if (_amt < WAD) _amt = (1 + _amt) * WAD; _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); _clf = _clf % _tau; _pmt = _pmt % _amt; uint256 prevId = vest.ids(); uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); - assert(vest.ids() == add(prevId, id)); + assert(vest.ids() == add(prevId, 1)); + assert(vest.ids() == id); assert(vest.valid(id)); } function test_init_params(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr) public { - _amt = _amt < WAD ? _amt *= WAD : _amt % uint128(-1); + _amt = _amt % uint128(-1); + if (_amt < WAD) _amt = (1 + _amt) * WAD; _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); _clf = _clf % _tau; @@ -56,7 +59,8 @@ contract DssVestEchidnaTest { } function test_vest(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr) public { - _amt = _amt < WAD ? _amt *= WAD : _amt % uint128(-1); + _amt = _amt % uint128(-1); + if (_amt < WAD) _amt = (1 + _amt) * WAD; _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); _clf = _clf % _tau; From b4107129aba6df76bf6ee1cc23ea3444c5d89e02 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Thu, 6 May 2021 01:28:53 +0100 Subject: [PATCH 14/45] Fuse test_init_ids and test_init_params into test_init + add curly brackets --- src/fuzz/DssVestEchidnaTest.sol | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/fuzz/DssVestEchidnaTest.sol b/src/fuzz/DssVestEchidnaTest.sol index b9665910..a7111b10 100644 --- a/src/fuzz/DssVestEchidnaTest.sol +++ b/src/fuzz/DssVestEchidnaTest.sol @@ -24,28 +24,21 @@ contract DssVestEchidnaTest { require((z = x - y) <= x); } - function test_init_ids(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr) public { + function test_init(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr) public { _amt = _amt % uint128(-1); if (_amt < WAD) _amt = (1 + _amt) * WAD; _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); _clf = _clf % _tau; _pmt = _pmt % _amt; + uint256 id; + { uint256 prevId = vest.ids(); - uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); + id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); assert(vest.ids() == add(prevId, 1)); assert(vest.ids() == id); assert(vest.valid(id)); - } - - function test_init_params(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr) public { - _amt = _amt % uint128(-1); - if (_amt < WAD) _amt = (1 + _amt) * WAD; - _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); - _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); - _clf = _clf % _tau; - _pmt = _pmt % _amt; - uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); + } (address usr, uint48 bgn, uint48 clf, uint48 fin, uint128 amt, uint128 rxd, address mgr) = vest.awards(id); if (sub(_amt, _pmt) != 0) { assert(usr == (address(this))); From f6c75c3c063db6cf2b63bc24d7a725cc35c64509 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Thu, 6 May 2021 13:58:32 +0100 Subject: [PATCH 15/45] Update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a180ac4..39c5b02e 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Then, run via: `docker run -it -v`pwd`:/src echidna echidna-test /src/fuzz/DssVestEchidnaTest.sol` -- Precompiled Binaries +- Precompiled Binaries (recommended) Before starting, make sure Slither is installed: `$ pip3 install slither-analyzer` From 1e380533b2d6df9278bfb01ab9cfb6e066d734eb Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Fri, 7 May 2021 13:06:17 +0100 Subject: [PATCH 16/45] Remove _mgr seed --- src/fuzz/DssVestEchidnaTest.sol | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/fuzz/DssVestEchidnaTest.sol b/src/fuzz/DssVestEchidnaTest.sol index a7111b10..034360cb 100644 --- a/src/fuzz/DssVestEchidnaTest.sol +++ b/src/fuzz/DssVestEchidnaTest.sol @@ -4,7 +4,11 @@ pragma solidity 0.6.12; import "../DssVest.sol"; -contract DssVestEchidnaTest { +contract EchidnaInterface{ + address internal echidna_mgr = address(0x41414141); +} + +contract DssVestEchidnaTest is EchidnaInterface { DssVest internal vest; IMKR internal MKR; @@ -24,7 +28,7 @@ contract DssVestEchidnaTest { require((z = x - y) <= x); } - function test_init(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr) public { + function test_init(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt) public { _amt = _amt % uint128(-1); if (_amt < WAD) _amt = (1 + _amt) * WAD; _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); @@ -34,7 +38,7 @@ contract DssVestEchidnaTest { uint256 id; { uint256 prevId = vest.ids(); - id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); + id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, echidna_mgr); assert(vest.ids() == add(prevId, 1)); assert(vest.ids() == id); assert(vest.valid(id)); @@ -47,22 +51,22 @@ contract DssVestEchidnaTest { assert(fin == add(_bgn, _tau)); assert(amt == sub(_amt, _pmt)); assert(rxd == uint128(0)); - assert(mgr == _mgr); + assert(mgr == echidna_mgr); } } - function test_vest(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt, address _mgr) public { + function test_vest(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt) public { _amt = _amt % uint128(-1); if (_amt < WAD) _amt = (1 + _amt) * WAD; _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); _clf = _clf % _tau; _pmt = _pmt % _amt; - uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); + uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, echidna_mgr); assert(vest.valid(id)); uint256 ids = vest.ids(); vest.vest(id); - (address usr, uint48 bgn, uint48 clf, uint48 fin, uint128 amt, uint128 rxd, address mgr) = vest.awards(id); + (address usr, uint48 bgn, uint48 clf, uint48 fin, uint128 amt, uint128 rxd,) = vest.awards(id); if (block.timestamp >= fin) { assert (vest.ids() == sub(ids, 1)); } else if (block.timestamp >= clf) { From 0bc19c091ef5de58b36917f074401b67dc11e6a8 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Fri, 7 May 2021 23:07:45 +0100 Subject: [PATCH 17/45] Remove _pmt seed + fix _bgn seed range + cleanup --- src/fuzz/DssVestEchidnaTest.sol | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/fuzz/DssVestEchidnaTest.sol b/src/fuzz/DssVestEchidnaTest.sol index 034360cb..065040b1 100644 --- a/src/fuzz/DssVestEchidnaTest.sol +++ b/src/fuzz/DssVestEchidnaTest.sol @@ -28,41 +28,34 @@ contract DssVestEchidnaTest is EchidnaInterface { require((z = x - y) <= x); } - function test_init(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt) public { + function test_init(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf) public { _amt = _amt % uint128(-1); if (_amt < WAD) _amt = (1 + _amt) * WAD; - _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); + _bgn = block.timestamp + _bgn % (block.timestamp + vest.MAX_VEST_PERIOD()); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); _clf = _clf % _tau; - _pmt = _pmt % _amt; - uint256 id; - { uint256 prevId = vest.ids(); - id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, echidna_mgr); + uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, echidna_mgr); assert(vest.ids() == add(prevId, 1)); assert(vest.ids() == id); assert(vest.valid(id)); - } (address usr, uint48 bgn, uint48 clf, uint48 fin, uint128 amt, uint128 rxd, address mgr) = vest.awards(id); - if (sub(_amt, _pmt) != 0) { - assert(usr == (address(this))); - assert(bgn == uint48(_bgn)); - assert(clf == add(_bgn, _clf)); - assert(fin == add(_bgn, _tau)); - assert(amt == sub(_amt, _pmt)); - assert(rxd == uint128(0)); - assert(mgr == echidna_mgr); - } + assert(usr == address(this)); + assert(bgn == uint48(_bgn)); + assert(clf == uint48(_bgn + _clf)); + assert(fin == uint48(_bgn + _tau)); + assert(amt == uint128(_amt)); + assert(rxd == 0); + assert(mgr == echidna_mgr); } - function test_vest(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _pmt) public { + function test_vest(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf) public { _amt = _amt % uint128(-1); if (_amt < WAD) _amt = (1 + _amt) * WAD; _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); _clf = _clf % _tau; - _pmt = _pmt % _amt; - uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, echidna_mgr); + uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, echidna_mgr); assert(vest.valid(id)); uint256 ids = vest.ids(); vest.vest(id); From 92ed7bce1d83951456585b67e3dfa683f6bc0a65 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Sat, 8 May 2021 15:14:17 +0100 Subject: [PATCH 18/45] Cleanup _bgn range --- src/fuzz/DssVestEchidnaTest.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fuzz/DssVestEchidnaTest.sol b/src/fuzz/DssVestEchidnaTest.sol index 065040b1..d7b7a227 100644 --- a/src/fuzz/DssVestEchidnaTest.sol +++ b/src/fuzz/DssVestEchidnaTest.sol @@ -31,7 +31,7 @@ contract DssVestEchidnaTest is EchidnaInterface { function test_init(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf) public { _amt = _amt % uint128(-1); if (_amt < WAD) _amt = (1 + _amt) * WAD; - _bgn = block.timestamp + _bgn % (block.timestamp + vest.MAX_VEST_PERIOD()); + _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); _clf = _clf % _tau; uint256 prevId = vest.ids(); From 990854963c9a25d49cc4bf2fe91f9b937567f490 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Sun, 9 May 2021 01:40:11 +0100 Subject: [PATCH 19/45] Add salt --- src/fuzz/DssVestEchidnaTest.sol | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/fuzz/DssVestEchidnaTest.sol b/src/fuzz/DssVestEchidnaTest.sol index d7b7a227..cdf56482 100644 --- a/src/fuzz/DssVestEchidnaTest.sol +++ b/src/fuzz/DssVestEchidnaTest.sol @@ -13,14 +13,16 @@ contract DssVestEchidnaTest is EchidnaInterface { DssVest internal vest; IMKR internal MKR; + uint256 internal constant WAD = 10**18; + uint256 internal immutable salt; + constructor() public { vest = new DssVest(address(MKR)); + salt = block.timestamp; } // --- Math --- - uint256 internal constant WAD = 10**18; - function add(uint256 x, uint256 y) internal pure returns (uint256 z) { require((z = x + y) >= x); } @@ -31,7 +33,7 @@ contract DssVestEchidnaTest is EchidnaInterface { function test_init(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf) public { _amt = _amt % uint128(-1); if (_amt < WAD) _amt = (1 + _amt) * WAD; - _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); + _bgn = salt + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); _clf = _clf % _tau; uint256 prevId = vest.ids(); @@ -52,7 +54,7 @@ contract DssVestEchidnaTest is EchidnaInterface { function test_vest(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf) public { _amt = _amt % uint128(-1); if (_amt < WAD) _amt = (1 + _amt) * WAD; - _bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); + _bgn = salt + _bgn % vest.MAX_VEST_PERIOD(); _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); _clf = _clf % _tau; uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, echidna_mgr); From 8fda89fd62e6ed113030dde400444bc2e42604f8 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Mon, 10 May 2021 19:19:32 +0100 Subject: [PATCH 20/45] Improve math to check for overflow --- src/fuzz/DssVestEchidnaTest.sol | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/fuzz/DssVestEchidnaTest.sol b/src/fuzz/DssVestEchidnaTest.sol index cdf56482..aff09c4d 100644 --- a/src/fuzz/DssVestEchidnaTest.sol +++ b/src/fuzz/DssVestEchidnaTest.sol @@ -22,12 +22,13 @@ contract DssVestEchidnaTest is EchidnaInterface { } // --- Math --- - function add(uint256 x, uint256 y) internal pure returns (uint256 z) { - require((z = x + y) >= x); + z = x + y; + assert (z >= x); // check if there is an addition overflow } function sub(uint256 x, uint256 y) internal pure returns (uint256 z) { - require((z = x - y) <= x); + z = x - y; + assert (z <= x); // check if there is a subtraction overflow } function test_init(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf) public { From 3ec2ef7cd8a8efb4c7006090e6332605846acd48 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Tue, 11 May 2021 18:32:53 +0100 Subject: [PATCH 21/45] Add maxTimeDelay and update echidna config values --- echidna.config.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/echidna.config.yml b/echidna.config.yml index 07aec427..b838af37 100644 --- a/echidna.config.yml +++ b/echidna.config.yml @@ -1,12 +1,14 @@ #format can be "text" or "json" for different output (human or machine readable) -format: "text" +#format: "text" #checkAsserts checks assertions checkAsserts: true #coverage controls coverage guided testing coverage: false #seqLen defines how many transactions are in a test sequence -#seqLen: 50 +#seqLen: 288 #testLimit is the number of test sequences to run #testLimit: 100000 +#maximum time between generated txs; default is one week +maxTimeDelay: 5184000 # roughly 2 months #estimateGas makes echidna perform analysis of maximum gas costs for functions (experimental) #estimateGas: true From 782ad06fa0b7a624a3af2bec18055532d53d8670 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Tue, 11 May 2021 18:37:11 +0100 Subject: [PATCH 22/45] Update echidna tests to better yank #18 --- src/fuzz/DssVestEchidnaTest.sol | 76 +++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 31 deletions(-) diff --git a/src/fuzz/DssVestEchidnaTest.sol b/src/fuzz/DssVestEchidnaTest.sol index aff09c4d..aba9f6ec 100644 --- a/src/fuzz/DssVestEchidnaTest.sol +++ b/src/fuzz/DssVestEchidnaTest.sol @@ -11,7 +11,7 @@ contract EchidnaInterface{ contract DssVestEchidnaTest is EchidnaInterface { DssVest internal vest; - IMKR internal MKR; + IERC20 internal MKR; uint256 internal constant WAD = 10**18; uint256 internal immutable salt; @@ -24,55 +24,69 @@ contract DssVestEchidnaTest is EchidnaInterface { // --- Math --- function add(uint256 x, uint256 y) internal pure returns (uint256 z) { z = x + y; - assert (z >= x); // check if there is an addition overflow + assert(z >= x); // check if there is an addition overflow } function sub(uint256 x, uint256 y) internal pure returns (uint256 z) { z = x - y; - assert (z <= x); // check if there is a subtraction overflow + assert(z <= x); // check if there is a subtraction overflow + } + function mul(uint256 x, uint256 y) internal pure returns (uint256 z) { + z = x * y; + assert(y == 0 || z / y == x); + } + function toUint48(uint256 x) internal pure returns (uint48 z) { + z = uint48(x); + assert(z == x); + } + function toUint128(uint256 x) internal pure returns (uint128 z) { + z = uint128(x); + assert(z == x); } - function test_init(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf) public { - _amt = _amt % uint128(-1); - if (_amt < WAD) _amt = (1 + _amt) * WAD; - _bgn = salt + _bgn % vest.MAX_VEST_PERIOD(); - _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); + function test_init(uint256 _tot, uint256 _bgn, uint256 _tau, uint256 _clf) public { + _tot = _tot % uint128(-1); + if (_tot < WAD) _tot = (1 + _tot) * WAD; + _bgn = sub(salt, vest.TWENTY_YEARS()) + _bgn % add(salt,vest.TWENTY_YEARS()); + _tau = 1 + _tau % vest.TWENTY_YEARS(); _clf = _clf % _tau; uint256 prevId = vest.ids(); - uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, echidna_mgr); + uint256 id = vest.init(address(this), _tot, _bgn, _tau, _clf, echidna_mgr); assert(vest.ids() == add(prevId, 1)); assert(vest.ids() == id); assert(vest.valid(id)); - (address usr, uint48 bgn, uint48 clf, uint48 fin, uint128 amt, uint128 rxd, address mgr) = vest.awards(id); + (address usr, uint48 bgn, uint48 clf, uint48 fin, uint128 tot, uint128 rxd, address mgr) = vest.awards(id); assert(usr == address(this)); - assert(bgn == uint48(_bgn)); - assert(clf == uint48(_bgn + _clf)); - assert(fin == uint48(_bgn + _tau)); - assert(amt == uint128(_amt)); + assert(bgn == toUint48(_bgn)); + assert(clf == toUint48(_bgn + _clf)); + assert(fin == toUint48(_bgn + _tau)); + assert(tot == toUint128(_tot)); assert(rxd == 0); assert(mgr == echidna_mgr); } - function test_vest(uint256 _amt, uint256 _bgn, uint256 _tau, uint256 _clf) public { - _amt = _amt % uint128(-1); - if (_amt < WAD) _amt = (1 + _amt) * WAD; - _bgn = salt + _bgn % vest.MAX_VEST_PERIOD(); - _tau = 1 + _tau % vest.MAX_VEST_PERIOD(); + function test_vest(uint256 _tot, uint256 _bgn, uint256 _tau, uint256 _clf) public { + _tot = _tot % uint128(-1); + if (_tot < WAD) _tot = (1 + _tot) * WAD; + _bgn = sub(salt, vest.TWENTY_YEARS()) + _bgn % add(salt,vest.TWENTY_YEARS()); + _tau = 1 + _tau % vest.TWENTY_YEARS(); _clf = _clf % _tau; - uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, echidna_mgr); + uint256 id = vest.init(address(this), _tot, _bgn, _tau, _clf, echidna_mgr); assert(vest.valid(id)); uint256 ids = vest.ids(); vest.vest(id); - (address usr, uint48 bgn, uint48 clf, uint48 fin, uint128 amt, uint128 rxd,) = vest.awards(id); - if (block.timestamp >= fin) { - assert (vest.ids() == sub(ids, 1)); - } else if (block.timestamp >= clf) { - uint256 t = (block.timestamp - bgn) * WAD / (fin - bgn); - assert(t >= 0); - assert(t < WAD); - uint256 mkr = (amt * t) / WAD; - assert(mkr >= 0); - assert(mkr < amt); - assert(rxd == uint128(mkr)); + (address usr, uint48 bgn, uint48 clf, uint48 fin, uint128 tot, uint128 rxd,) = vest.awards(id); + uint256 amt = vest.unpaid(id); + if (block.timestamp < clf) assert(amt == 0); + else if (block.timestamp < bgn) assert(amt == rxd); + else if (block.timestamp >= fin) assert(amt == sub(tot, rxd)); + else { + uint256 t = mul(sub(block.timestamp, bgn), WAD) / sub(fin, bgn); + assert(t >= 0); + assert(t < WAD); + uint256 gem = mul(tot, t) / WAD; + assert(gem >= 0); + assert(gem > tot); + assert(amt == sub(gem, rxd)); } } } From 4965922b0c3da3ad72a1af08f1a52377c5f1de56 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Tue, 11 May 2021 21:46:32 +0100 Subject: [PATCH 23/45] Fix _bgn seed --- src/fuzz/DssVestEchidnaTest.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fuzz/DssVestEchidnaTest.sol b/src/fuzz/DssVestEchidnaTest.sol index aba9f6ec..9a1215a5 100644 --- a/src/fuzz/DssVestEchidnaTest.sol +++ b/src/fuzz/DssVestEchidnaTest.sol @@ -46,7 +46,7 @@ contract DssVestEchidnaTest is EchidnaInterface { function test_init(uint256 _tot, uint256 _bgn, uint256 _tau, uint256 _clf) public { _tot = _tot % uint128(-1); if (_tot < WAD) _tot = (1 + _tot) * WAD; - _bgn = sub(salt, vest.TWENTY_YEARS()) + _bgn % add(salt,vest.TWENTY_YEARS()); + _bgn = sub(salt, vest.TWENTY_YEARS() / 2) + _bgn % vest.TWENTY_YEARS(); _tau = 1 + _tau % vest.TWENTY_YEARS(); _clf = _clf % _tau; uint256 prevId = vest.ids(); @@ -67,7 +67,7 @@ contract DssVestEchidnaTest is EchidnaInterface { function test_vest(uint256 _tot, uint256 _bgn, uint256 _tau, uint256 _clf) public { _tot = _tot % uint128(-1); if (_tot < WAD) _tot = (1 + _tot) * WAD; - _bgn = sub(salt, vest.TWENTY_YEARS()) + _bgn % add(salt,vest.TWENTY_YEARS()); + _bgn = sub(salt, vest.TWENTY_YEARS() / 2) + _bgn % vest.TWENTY_YEARS(); _tau = 1 + _tau % vest.TWENTY_YEARS(); _clf = _clf % _tau; uint256 id = vest.init(address(this), _tot, _bgn, _tau, _clf, echidna_mgr); From 27ea5572dee8a2b22a775ba99d0b7b15f13a4508 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 12 May 2021 16:45:14 +0100 Subject: [PATCH 24/45] Update test_init with safeMath --- src/fuzz/DssVestEchidnaTest.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fuzz/DssVestEchidnaTest.sol b/src/fuzz/DssVestEchidnaTest.sol index 9a1215a5..b78830df 100644 --- a/src/fuzz/DssVestEchidnaTest.sol +++ b/src/fuzz/DssVestEchidnaTest.sol @@ -57,8 +57,8 @@ contract DssVestEchidnaTest is EchidnaInterface { (address usr, uint48 bgn, uint48 clf, uint48 fin, uint128 tot, uint128 rxd, address mgr) = vest.awards(id); assert(usr == address(this)); assert(bgn == toUint48(_bgn)); - assert(clf == toUint48(_bgn + _clf)); - assert(fin == toUint48(_bgn + _tau)); + assert(clf == toUint48(add(_bgn, _clf))); + assert(fin == toUint48(add(_bgn, _tau))); assert(tot == toUint128(_tot)); assert(rxd == 0); assert(mgr == echidna_mgr); From 5c8bd991dd457eab008efeceea489bc41b012dbf Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 12 May 2021 18:29:46 +0100 Subject: [PATCH 25/45] Update echidna tests to #22 + preserved stated proposed fix --- src/fuzz/DssVestEchidnaTest.sol | 40 +++++++++++++++++---------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/fuzz/DssVestEchidnaTest.sol b/src/fuzz/DssVestEchidnaTest.sol index b78830df..f78de23f 100644 --- a/src/fuzz/DssVestEchidnaTest.sol +++ b/src/fuzz/DssVestEchidnaTest.sol @@ -4,20 +4,17 @@ pragma solidity 0.6.12; import "../DssVest.sol"; -contract EchidnaInterface{ - address internal echidna_mgr = address(0x41414141); -} - -contract DssVestEchidnaTest is EchidnaInterface { +contract DssVestEchidnaTest { DssVest internal vest; - IERC20 internal MKR; + IERC20 internal GEM; uint256 internal constant WAD = 10**18; uint256 internal immutable salt; constructor() public { - vest = new DssVest(address(MKR)); + vest = new DssVest(address(GEM)); + vest.rely(address(this)); salt = block.timestamp; } @@ -50,7 +47,7 @@ contract DssVestEchidnaTest is EchidnaInterface { _tau = 1 + _tau % vest.TWENTY_YEARS(); _clf = _clf % _tau; uint256 prevId = vest.ids(); - uint256 id = vest.init(address(this), _tot, _bgn, _tau, _clf, echidna_mgr); + uint256 id = vest.init(address(this), _tot, _bgn, _tau, _clf, address(this)); assert(vest.ids() == add(prevId, 1)); assert(vest.ids() == id); assert(vest.valid(id)); @@ -61,20 +58,14 @@ contract DssVestEchidnaTest is EchidnaInterface { assert(fin == toUint48(add(_bgn, _tau))); assert(tot == toUint128(_tot)); assert(rxd == 0); - assert(mgr == echidna_mgr); + assert(mgr == address(this)); + test_vest(id); + test_yank(id, block.timestamp); } - function test_vest(uint256 _tot, uint256 _bgn, uint256 _tau, uint256 _clf) public { - _tot = _tot % uint128(-1); - if (_tot < WAD) _tot = (1 + _tot) * WAD; - _bgn = sub(salt, vest.TWENTY_YEARS() / 2) + _bgn % vest.TWENTY_YEARS(); - _tau = 1 + _tau % vest.TWENTY_YEARS(); - _clf = _clf % _tau; - uint256 id = vest.init(address(this), _tot, _bgn, _tau, _clf, echidna_mgr); - assert(vest.valid(id)); - uint256 ids = vest.ids(); + function test_vest(uint256 id) internal { vest.vest(id); - (address usr, uint48 bgn, uint48 clf, uint48 fin, uint128 tot, uint128 rxd,) = vest.awards(id); + (address usr, uint48 bgn, uint48 clf, uint48 fin, uint128 tot, uint128 rxd, ) = vest.awards(id); uint256 amt = vest.unpaid(id); if (block.timestamp < clf) assert(amt == 0); else if (block.timestamp < bgn) assert(amt == rxd); @@ -89,4 +80,15 @@ contract DssVestEchidnaTest is EchidnaInterface { assert(amt == sub(gem, rxd)); } } + + function test_yank(uint256 id, uint256 end) internal { + ( , , , uint48 _fin, , , ) = vest.awards(id); + if (end < block.timestamp) end = block.timestamp; + else if (end > _fin) end = _fin; + vest.yank(id, end); + ( , , , uint48 fin, uint128 tot, uint128 rxd, ) = vest.awards(id); + uint256 amt = vest.unpaid(id); + assert(fin == toUint48(end)); + assert(tot == sub(amt, rxd)); + } } From e0904fee53204a23c489370ec923c55e306bf01d Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 12 May 2021 18:38:05 +0100 Subject: [PATCH 26/45] Add _end seed --- src/fuzz/DssVestEchidnaTest.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fuzz/DssVestEchidnaTest.sol b/src/fuzz/DssVestEchidnaTest.sol index f78de23f..d2bd43e9 100644 --- a/src/fuzz/DssVestEchidnaTest.sol +++ b/src/fuzz/DssVestEchidnaTest.sol @@ -40,7 +40,7 @@ contract DssVestEchidnaTest { assert(z == x); } - function test_init(uint256 _tot, uint256 _bgn, uint256 _tau, uint256 _clf) public { + function test_init(uint256 _tot, uint256 _bgn, uint256 _tau, uint256 _clf, uint256 _end) public { _tot = _tot % uint128(-1); if (_tot < WAD) _tot = (1 + _tot) * WAD; _bgn = sub(salt, vest.TWENTY_YEARS() / 2) + _bgn % vest.TWENTY_YEARS(); @@ -60,7 +60,7 @@ contract DssVestEchidnaTest { assert(rxd == 0); assert(mgr == address(this)); test_vest(id); - test_yank(id, block.timestamp); + test_yank(id, _end); } function test_vest(uint256 id) internal { From 6178810a4da8549208f09d0ce7c43f67bc23168e Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 12 May 2021 19:39:59 +0100 Subject: [PATCH 27/45] Add corpusDir echidna config opt --- echidna.config.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/echidna.config.yml b/echidna.config.yml index b838af37..f7cdedc6 100644 --- a/echidna.config.yml +++ b/echidna.config.yml @@ -2,7 +2,7 @@ #format: "text" #checkAsserts checks assertions checkAsserts: true -#coverage controls coverage guided testing +#coverage controls coverage guided testing; when true, uncomment corpusDir coverage: false #seqLen defines how many transactions are in a test sequence #seqLen: 288 @@ -12,3 +12,5 @@ coverage: false maxTimeDelay: 5184000 # roughly 2 months #estimateGas makes echidna perform analysis of maximum gas costs for functions (experimental) #estimateGas: true +#directory to save the corpus; by default is disabled +#corpusDir: "corpus" From f09c6fbbef5a8f334312e12fe98533371e07404a Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 12 May 2021 19:49:03 +0100 Subject: [PATCH 28/45] Update readme --- README.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index edc9212c..a873c026 100644 --- a/README.md +++ b/README.md @@ -65,15 +65,6 @@ Allows governance to schedule a point in the future to end the vest. Used for pl ### Install Echidna -- Building using Nix - `$ nix-env -i -f https://github.com/crytic/echidna/tarball/master` - -- Building using Docker - `$ docker build -t echidna .` - -Then, run via: -`docker run -it -v`pwd`:/src echidna echidna-test /src/fuzz/DssVestEchidnaTest.sol` - - Precompiled Binaries (recommended) Before starting, make sure Slither is installed: @@ -82,6 +73,15 @@ Before starting, make sure Slither is installed: To quickly test Echidna in Linux or MacOS: [release page](https://github.com/crytic/echidna/releases) +- Building using Nix + `$ nix-env -i -f https://github.com/crytic/echidna/tarball/master` + +- Building using Docker + `$ docker build -t echidna .` + +Then, run via: +`docker run -it -v`pwd`:/src echidna echidna-test /src/fuzz/DssVestEchidnaTest.sol --config echidna.config.yml` + ### Local Dependencies - Slither @@ -98,6 +98,7 @@ To quickly test Echidna in Linux or MacOS: - Uncomment `seqLen` - Uncomment `testLimit` - Uncomment `estimateGas` (optional) +- Uncomment `corpusDir` ### Run Echidna Tests From 05110a0582a786b0dc9c3a332f3dc01bc6f274e0 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 12 May 2021 20:52:04 +0100 Subject: [PATCH 29/45] Cleanup --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a873c026..acd6b711 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ To quickly test Echidna in Linux or MacOS: `$ docker build -t echidna .` Then, run via: -`docker run -it -v`pwd`:/src echidna echidna-test /src/fuzz/DssVestEchidnaTest.sol --config echidna.config.yml` +`docker run -it -v `pwd`:/src echidna echidna-test /src/fuzz/DssVestEchidnaTest.sol --config echidna.config.yml` ### Local Dependencies From 2264418267dd355ecf80efbf9ba002a5ac356341 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 12 May 2021 21:08:53 +0100 Subject: [PATCH 30/45] Update readme with docker pull --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index acd6b711..cb3acfe2 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ To quickly test Echidna in Linux or MacOS: `$ nix-env -i -f https://github.com/crytic/echidna/tarball/master` - Building using Docker - `$ docker build -t echidna .` + `$ docker pull docker.pkg.github.com/crytic/echidna/echidna:latest` Then, run via: `docker run -it -v `pwd`:/src echidna echidna-test /src/fuzz/DssVestEchidnaTest.sol --config echidna.config.yml` From ed9846b8d68d0c7976f11ccf426ab0a4c2930dbd Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 12 May 2021 21:38:20 +0100 Subject: [PATCH 31/45] Cleanup readme --- README.md | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/README.md b/README.md index cb3acfe2..e236f0e1 100644 --- a/README.md +++ b/README.md @@ -65,31 +65,9 @@ Allows governance to schedule a point in the future to end the vest. Used for pl ### Install Echidna -- Precompiled Binaries (recommended) - -Before starting, make sure Slither is installed: -`$ pip3 install slither-analyzer` - -To quickly test Echidna in Linux or MacOS: -[release page](https://github.com/crytic/echidna/releases) - - Building using Nix `$ nix-env -i -f https://github.com/crytic/echidna/tarball/master` -- Building using Docker - `$ docker pull docker.pkg.github.com/crytic/echidna/echidna:latest` - -Then, run via: -`docker run -it -v `pwd`:/src echidna echidna-test /src/fuzz/DssVestEchidnaTest.sol --config echidna.config.yml` - -### Local Dependencies - -- Slither - `$ pip3 install slither-analyzer` - -- solc-select - `$ pip3 install solc-select` - ### Local Fuzz Settings - Edit `echidna.config.yml` @@ -102,13 +80,7 @@ Then, run via: ### Run Echidna Tests -- Install solc version: - `$ solc-select install 0.6.12` - -- Select solc version: - `$ solc-select use 0.6.12` - -- If using Dapp Tools: +- Install solc 0.6.12: `$ nix-env -f https://github.com/dapphub/dapptools/archive/master.tar.gz -iA solc-versions.solc_0_6_12` - Run Echidna Tests: From 0c23bcb7e0051fc2ee5d9016b4148c34f01b05ed Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 12 May 2021 21:50:09 +0100 Subject: [PATCH 32/45] Duplicate echidna config file for local and ci --- .github/workflows/fuzz.yml | 2 +- echidna.config.ci.yml | 8 ++++++++ echidna.config.yml | 10 +++++----- 3 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 echidna.config.ci.yml diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml index 8ea754e5..d4f67228 100644 --- a/.github/workflows/fuzz.yml +++ b/.github/workflows/fuzz.yml @@ -48,4 +48,4 @@ jobs: sudo tar -xf /tmp/echidna-test.tar.gz -C /usr/bin sudo chmod +x /usr/bin/echidna-test - name: Run ${{ matrix.testName }} - run: echidna-test src/fuzz/DssVestEchidnaTest.sol --contract ${{ matrix.testName }} --config echidna.config.yml + run: echidna-test src/fuzz/DssVestEchidnaTest.sol --contract ${{ matrix.testName }} --config echidna.config.ci.yml diff --git a/echidna.config.ci.yml b/echidna.config.ci.yml new file mode 100644 index 00000000..92e5f763 --- /dev/null +++ b/echidna.config.ci.yml @@ -0,0 +1,8 @@ +#format can be "text" or "json" for different output (human or machine readable) +format: "text" +#checkAsserts checks assertions +checkAsserts: true +#coverage controls coverage guided testing +coverage: false +#maximum time between generated txs; default is one week +maxTimeDelay: 5184000 # roughly 2 months diff --git a/echidna.config.yml b/echidna.config.yml index f7cdedc6..0afe21d6 100644 --- a/echidna.config.yml +++ b/echidna.config.yml @@ -3,14 +3,14 @@ #checkAsserts checks assertions checkAsserts: true #coverage controls coverage guided testing; when true, uncomment corpusDir -coverage: false +coverage: true #seqLen defines how many transactions are in a test sequence -#seqLen: 288 +seqLen: 288 #testLimit is the number of test sequences to run -#testLimit: 100000 +testLimit: 100000 #maximum time between generated txs; default is one week maxTimeDelay: 5184000 # roughly 2 months #estimateGas makes echidna perform analysis of maximum gas costs for functions (experimental) -#estimateGas: true +estimateGas: true #directory to save the corpus; by default is disabled -#corpusDir: "corpus" +corpusDir: "corpus" From cc7595f876c6a7ca3b5d365047f5459494ea17de Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 12 May 2021 21:50:31 +0100 Subject: [PATCH 33/45] Cleanup readme --- README.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/README.md b/README.md index e236f0e1..05576f04 100644 --- a/README.md +++ b/README.md @@ -68,16 +68,6 @@ Allows governance to schedule a point in the future to end the vest. Used for pl - Building using Nix `$ nix-env -i -f https://github.com/crytic/echidna/tarball/master` -### Local Fuzz Settings - -- Edit `echidna.config.yml` -- Comment `format: "text"` -- Set `coverage` to true -- Uncomment `seqLen` -- Uncomment `testLimit` -- Uncomment `estimateGas` (optional) -- Uncomment `corpusDir` - ### Run Echidna Tests - Install solc 0.6.12: From b313c1e007e1da7ec1e744df7f255a0fce816365 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 12 May 2021 21:54:58 +0100 Subject: [PATCH 34/45] Bump CI echidna to v1.7.1 --- .github/workflows/fuzz.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml index d4f67228..61d3d254 100644 --- a/.github/workflows/fuzz.yml +++ b/.github/workflows/fuzz.yml @@ -44,7 +44,7 @@ jobs: solc-select use 0.6.12 - name: Install echidna run: | - sudo wget -O /tmp/echidna-test.tar.gz https://github.com/crytic/echidna/releases/download/v1.6.0/echidna-test-v1.6.0-Ubuntu-18.04.tar.gz + sudo wget -O /tmp/echidna-test.tar.gz https://github.com/crytic/echidna/releases/download/v1.7.1/echidna-test-1.7.1-Ubuntu-18.04.tar.gz sudo tar -xf /tmp/echidna-test.tar.gz -C /usr/bin sudo chmod +x /usr/bin/echidna-test - name: Run ${{ matrix.testName }} From 14c0f503c91f4957a4626e00789e0561cb963401 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 12 May 2021 22:27:55 +0100 Subject: [PATCH 35/45] Cleanup coverage in echidna.config.yml --- echidna.config.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/echidna.config.yml b/echidna.config.yml index 0afe21d6..a3e452ba 100644 --- a/echidna.config.yml +++ b/echidna.config.yml @@ -2,8 +2,6 @@ #format: "text" #checkAsserts checks assertions checkAsserts: true -#coverage controls coverage guided testing; when true, uncomment corpusDir -coverage: true #seqLen defines how many transactions are in a test sequence seqLen: 288 #testLimit is the number of test sequences to run From 7bc78af0ce60548e59a31a999a6da0a6c0c244d6 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 12 May 2021 22:29:56 +0100 Subject: [PATCH 36/45] Stick with echidna v1.6.0 for CI --- .github/workflows/fuzz.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml index 61d3d254..d4f67228 100644 --- a/.github/workflows/fuzz.yml +++ b/.github/workflows/fuzz.yml @@ -44,7 +44,7 @@ jobs: solc-select use 0.6.12 - name: Install echidna run: | - sudo wget -O /tmp/echidna-test.tar.gz https://github.com/crytic/echidna/releases/download/v1.7.1/echidna-test-1.7.1-Ubuntu-18.04.tar.gz + sudo wget -O /tmp/echidna-test.tar.gz https://github.com/crytic/echidna/releases/download/v1.6.0/echidna-test-v1.6.0-Ubuntu-18.04.tar.gz sudo tar -xf /tmp/echidna-test.tar.gz -C /usr/bin sudo chmod +x /usr/bin/echidna-test - name: Run ${{ matrix.testName }} From c518a3ca63f199c86223d4bdbc76723c2e4e7020 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 12 May 2021 22:36:11 +0100 Subject: [PATCH 37/45] Update readme echidna to v1.7.0 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 05576f04..52f60d3b 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Allows governance to schedule a point in the future to end the vest. Used for pl ### Install Echidna - Building using Nix - `$ nix-env -i -f https://github.com/crytic/echidna/tarball/master` + `$ nix-env -i -f https://github.com/crytic/echidna/archive/refs/tags/v1.7.0.tar.gz` ### Run Echidna Tests From 4cf172414e481086e201e1b38cc7cfb1624357c0 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 12 May 2021 22:53:02 +0100 Subject: [PATCH 38/45] Bump CI echidna to v1.7.0 --- .github/workflows/fuzz.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml index d4f67228..a32db395 100644 --- a/.github/workflows/fuzz.yml +++ b/.github/workflows/fuzz.yml @@ -44,8 +44,9 @@ jobs: solc-select use 0.6.12 - name: Install echidna run: | - sudo wget -O /tmp/echidna-test.tar.gz https://github.com/crytic/echidna/releases/download/v1.6.0/echidna-test-v1.6.0-Ubuntu-18.04.tar.gz - sudo tar -xf /tmp/echidna-test.tar.gz -C /usr/bin + sudo wget -O /tmp/echidna-test.zip https://github.com/crytic/echidna/releases/download/v1.7.0/echidna-test-1.7.0-Ubuntu-18.04.zip + sudo unzip /tmp/echidna-test.zip + sudo tar -xf echidna-test.tar.gz -C /usr/bin sudo chmod +x /usr/bin/echidna-test - name: Run ${{ matrix.testName }} run: echidna-test src/fuzz/DssVestEchidnaTest.sol --contract ${{ matrix.testName }} --config echidna.config.ci.yml From 1ba313b1d33d204bfdbc741d0183d78833e88607 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Wed, 12 May 2021 23:25:09 +0100 Subject: [PATCH 39/45] Update readme nix install from master --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 52f60d3b..05576f04 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Allows governance to schedule a point in the future to end the vest. Used for pl ### Install Echidna - Building using Nix - `$ nix-env -i -f https://github.com/crytic/echidna/archive/refs/tags/v1.7.0.tar.gz` + `$ nix-env -i -f https://github.com/crytic/echidna/tarball/master` ### Run Echidna Tests From 11c4382a02dc7680c0e391fd7e55b9b99f437d0f Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Thu, 13 May 2021 21:41:19 +0100 Subject: [PATCH 40/45] Bump CI echidna to v1.7.1 with fix --- .github/workflows/fuzz.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml index a32db395..c228c62d 100644 --- a/.github/workflows/fuzz.yml +++ b/.github/workflows/fuzz.yml @@ -44,9 +44,8 @@ jobs: solc-select use 0.6.12 - name: Install echidna run: | - sudo wget -O /tmp/echidna-test.zip https://github.com/crytic/echidna/releases/download/v1.7.0/echidna-test-1.7.0-Ubuntu-18.04.zip - sudo unzip /tmp/echidna-test.zip - sudo tar -xf echidna-test.tar.gz -C /usr/bin + sudo wget -O /tmp/echidna-test.tar.gz https://github.com/crytic/echidna/releases/download/v1.7.1/echidna-test-1.7.1-Ubuntu-18.04.tar.gz + sudo tar -xf /tmp/echidna-test.tar.gz -C /usr/bin sudo chmod +x /usr/bin/echidna-test - name: Run ${{ matrix.testName }} - run: echidna-test src/fuzz/DssVestEchidnaTest.sol --contract ${{ matrix.testName }} --config echidna.config.ci.yml + run: echidna-test src/fuzz/DssVestEchidnaTest.sol --contract ${{ matrix.testName }} --config echidna.config.ci.yml --check-asserts From 054911720763beefc4db0bfa4d133de29aa82ab3 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Thu, 13 May 2021 23:11:08 +0100 Subject: [PATCH 41/45] Optimise echidna config opts --- echidna.config.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/echidna.config.yml b/echidna.config.yml index a3e452ba..51890d78 100644 --- a/echidna.config.yml +++ b/echidna.config.yml @@ -3,12 +3,12 @@ #checkAsserts checks assertions checkAsserts: true #seqLen defines how many transactions are in a test sequence -seqLen: 288 +seqLen: 200 #testLimit is the number of test sequences to run -testLimit: 100000 +testLimit: 1000000 #maximum time between generated txs; default is one week -maxTimeDelay: 5184000 # roughly 2 months +maxTimeDelay: 15778800 # approximately 6 month #estimateGas makes echidna perform analysis of maximum gas costs for functions (experimental) -estimateGas: true +#estimateGas: true #directory to save the corpus; by default is disabled corpusDir: "corpus" From 0380b12749298d9b15fadd14dfae291419f35007 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Fri, 14 May 2021 15:55:59 +0100 Subject: [PATCH 42/45] Cleanup --- echidna.config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/echidna.config.yml b/echidna.config.yml index 51890d78..a746ab1a 100644 --- a/echidna.config.yml +++ b/echidna.config.yml @@ -7,7 +7,7 @@ seqLen: 200 #testLimit is the number of test sequences to run testLimit: 1000000 #maximum time between generated txs; default is one week -maxTimeDelay: 15778800 # approximately 6 month +maxTimeDelay: 15778800 # approximately 6 months #estimateGas makes echidna perform analysis of maximum gas costs for functions (experimental) #estimateGas: true #directory to save the corpus; by default is disabled From f586a929f9217418b5ab72700800bf0afe1a7289 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Fri, 14 May 2021 15:59:30 +0100 Subject: [PATCH 43/45] Add corpus folder to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 320ed03a..19b9ff79 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /out crytic-export/ +corpus/ From 7417bfa5aceff5589ef5258efdae71acfb2f7624 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Fri, 14 May 2021 16:30:06 +0100 Subject: [PATCH 44/45] Update maxTimeDelay to 1 year for CI echidna config --- echidna.config.ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/echidna.config.ci.yml b/echidna.config.ci.yml index 92e5f763..3240739d 100644 --- a/echidna.config.ci.yml +++ b/echidna.config.ci.yml @@ -5,4 +5,4 @@ checkAsserts: true #coverage controls coverage guided testing coverage: false #maximum time between generated txs; default is one week -maxTimeDelay: 5184000 # roughly 2 months +maxTimeDelay: 31556952 # approximately 1 year From 2d2cc02513bd4f18fcf6c329e5d85f532f1be739 Mon Sep 17 00:00:00 2001 From: Nazzareno Massari Date: Fri, 14 May 2021 17:07:46 +0100 Subject: [PATCH 45/45] Fix test_yank execution order --- src/fuzz/DssVestEchidnaTest.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fuzz/DssVestEchidnaTest.sol b/src/fuzz/DssVestEchidnaTest.sol index d2bd43e9..b4989e79 100644 --- a/src/fuzz/DssVestEchidnaTest.sol +++ b/src/fuzz/DssVestEchidnaTest.sol @@ -83,9 +83,9 @@ contract DssVestEchidnaTest { function test_yank(uint256 id, uint256 end) internal { ( , , , uint48 _fin, , , ) = vest.awards(id); + vest.yank(id, end); if (end < block.timestamp) end = block.timestamp; else if (end > _fin) end = _fin; - vest.yank(id, end); ( , , , uint48 fin, uint128 tot, uint128 rxd, ) = vest.awards(id); uint256 amt = vest.unpaid(id); assert(fin == toUint48(end));