|
| 1 | +name: Run Medusa tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - ".github/workflows/medusa.yml" |
| 7 | + - "program-analysis/echidna/**/*.sol" |
| 8 | + - "program-analysis/echidna/**/*.yml" |
| 9 | + branches: |
| 10 | + - master |
| 11 | + pull_request: |
| 12 | + paths: |
| 13 | + - ".github/workflows/medusa.yml" |
| 14 | + - "program-analysis/echidna/**/*.sol" |
| 15 | + - "program-analysis/echidna/**/*.yml" |
| 16 | + schedule: |
| 17 | + # run CI every day even if no PRs/merges occur |
| 18 | + - cron: "0 12 * * *" |
| 19 | + |
| 20 | +jobs: |
| 21 | + tests: |
| 22 | + name: ${{ matrix.name }} |
| 23 | + continue-on-error: ${{ matrix.flaky == true }} |
| 24 | + runs-on: ubuntu-22.04 |
| 25 | + strategy: |
| 26 | + fail-fast: false |
| 27 | + matrix: |
| 28 | + include: |
| 29 | + - name: Exercise 1 |
| 30 | + workdir: program-analysis/echidna/exercises/exercise1/ |
| 31 | + files: solution.sol |
| 32 | + contract: TestToken |
| 33 | + outcome: failure |
| 34 | + expected: 'echidna_test_balance()\" failed after the following call sequence' |
| 35 | + - name: Exercise 2 |
| 36 | + workdir: program-analysis/echidna/exercises/exercise2/ |
| 37 | + files: solution.sol |
| 38 | + contract: TestToken |
| 39 | + outcome: failure |
| 40 | + expected: 'echidna_no_transfer()\" failed after the following call sequence' |
| 41 | + - name: Exercise 3 |
| 42 | + workdir: program-analysis/echidna/exercises/exercise3/ |
| 43 | + files: solution.sol |
| 44 | + contract: TestToken |
| 45 | + outcome: failure |
| 46 | + expected: 'echidna_test_balance()\" failed after the following call sequence' |
| 47 | + - name: Exercise 4 |
| 48 | + workdir: program-analysis/echidna/exercises/exercise4/ |
| 49 | + files: solution.sol |
| 50 | + contract: TestToken |
| 51 | + outcome: failure |
| 52 | + expected: 'transfer(address,uint256)\" resulted in an assertion failure after the following call sequence:' |
| 53 | + # - name: Exercise 5 |
| 54 | + # workdir: dvdefi/ |
| 55 | + # files: . |
| 56 | + # config: naivereceiver.yaml |
| 57 | + # crytic-args: --hardhat-ignore-compile |
| 58 | + # contract: NaiveReceiverEchidna |
| 59 | + # outcome: failure |
| 60 | + # expected: 'echidna_test_contract_balance:\s*failed' |
| 61 | + # - name: Exercise 6 |
| 62 | + # workdir: dvdefi/ |
| 63 | + # files: . |
| 64 | + # config: unstoppable.yaml |
| 65 | + # crytic-args: --hardhat-ignore-compile |
| 66 | + # contract: UnstoppableEchidna |
| 67 | + # outcome: failure |
| 68 | + # expected: 'echidna_testFlashLoan:\s*failed' |
| 69 | + # - name: Exercise 7 |
| 70 | + # workdir: dvdefi/ |
| 71 | + # files: . |
| 72 | + # config: sideentrance.yaml |
| 73 | + # crytic-args: --hardhat-ignore-compile |
| 74 | + # contract: SideEntranceEchidna |
| 75 | + # outcome: failure |
| 76 | + # expected: 'testPoolBalance():\s*failed' |
| 77 | + - name: TestToken |
| 78 | + workdir: program-analysis/echidna/example/ |
| 79 | + files: testtoken.sol |
| 80 | + contract: TestToken |
| 81 | + outcome: failure |
| 82 | + expected: 'echidna_balance_under_1000()\" failed after the following call sequence' |
| 83 | + - name: Multi |
| 84 | + workdir: program-analysis/echidna/example/ |
| 85 | + files: multi.sol |
| 86 | + contract: C |
| 87 | + config: filter.yaml |
| 88 | + outcome: failure |
| 89 | + expected: 'echidna_state4()\" failed after the following call sequence' |
| 90 | + - name: Assert |
| 91 | + workdir: program-analysis/echidna/example/ |
| 92 | + files: assert.sol |
| 93 | + config: assert.yaml |
| 94 | + contract: Incrementor |
| 95 | + outcome: failure |
| 96 | + expected: 'inc(uint256)\" resulted in an assertion failure after the following call sequence' |
| 97 | + - name: PopsicleBroken |
| 98 | + workdir: program-analysis/echidna/example/ |
| 99 | + files: PopsicleBroken.sol |
| 100 | + solc-version: 0.8.4 |
| 101 | + contract: PopsicleBroken |
| 102 | + outcome: failure |
| 103 | + expected: 'PopsicleBroken.totalBalanceAfterTransferIsPreserved(address,uint256)\" resulted in an assertion failure after the following call sequence' |
| 104 | + - name: PopsicleFixed |
| 105 | + workdir: program-analysis/echidna/example/ |
| 106 | + files: PopsicleFixed.sol |
| 107 | + solc-version: 0.8.4 |
| 108 | + contract: PopsicleFixed |
| 109 | + outcome: success |
| 110 | + expected: '\[PASSED\] Assertion Test: PopsicleFixed.totalBalanceAfterTransferIsPreserved(address,uint256)' |
| 111 | + - name: TestDepositWithPermit |
| 112 | + workdir: program-analysis/echidna/example/ |
| 113 | + files: TestDepositWithPermit.sol |
| 114 | + solc-version: 0.8.0 |
| 115 | + config: testdeposit.yaml |
| 116 | + contract: TestDepositWithPermit |
| 117 | + outcome: success |
| 118 | + expected: '\[PASSED\] Assertion Test: TestDepositWithPermit.testERC20PermitDeposit(uint256)' |
| 119 | + # - name: MultiABI |
| 120 | + # workdir: program-analysis/echidna/example/ |
| 121 | + # files: allContracts.sol |
| 122 | + # solc-version: 0.8.0 |
| 123 | + # config: allContracts.yaml |
| 124 | + # contract: EchidnaTest |
| 125 | + # outcome: failure |
| 126 | + # expected: 'test_flag_is_false():\s*failed' |
| 127 | + |
| 128 | + steps: |
| 129 | + - name: Checkout repository |
| 130 | + uses: actions/checkout@v4 |
| 131 | + |
| 132 | + - name: Checkout Damn Vulnerable DeFi solutions |
| 133 | + uses: actions/checkout@v4 |
| 134 | + if: startsWith(matrix.workdir, 'dvdefi') |
| 135 | + with: |
| 136 | + repository: crytic/damn-vulnerable-defi-echidna |
| 137 | + ref: solutions |
| 138 | + path: ${{ matrix.workdir }} |
| 139 | + |
| 140 | + - name: Set up Nodejs |
| 141 | + uses: actions/setup-node@v3 |
| 142 | + if: startsWith(matrix.workdir, 'dvdefi') |
| 143 | + with: |
| 144 | + node-version: 16 |
| 145 | + |
| 146 | + - name: Install dependencies and compile |
| 147 | + if: startsWith(matrix.workdir, 'dvdefi') |
| 148 | + run: | |
| 149 | + yarn install --frozen-lockfile |
| 150 | + npx hardhat compile --force |
| 151 | + working-directory: ${{ matrix.workdir }} |
| 152 | + |
| 153 | + - name: Go setup |
| 154 | + uses: actions/setup-go@v5 |
| 155 | + with: |
| 156 | + go-version: "^1.18.1" |
| 157 | + |
| 158 | + - name: Install medusa |
| 159 | + run: | |
| 160 | + git clone https://github.com/crytic/medusa.git |
| 161 | + cd medusa |
| 162 | + go build -o medusa -v . |
| 163 | + go install -v . |
| 164 | + sudo cp medusa /usr/bin |
| 165 | + pip install crytic-compile solc-select |
| 166 | +
|
| 167 | + - name: Run Medusa |
| 168 | + continue-on-error: true |
| 169 | + working-directory: ${{ matrix.workdir }} |
| 170 | + run: | |
| 171 | + solc-select install ${{ matrix.solc-version || '0.8.0' }} |
| 172 | + solc-select use ${{ matrix.solc-version || '0.8.0' }} |
| 173 | + medusa fuzz --compilation-target ${{ matrix.files }} --target-contracts ${{ matrix.contract }} --no-color --test-limit 100000 --config medusa.json > ${{ matrix.files }}.out || true |
| 174 | +
|
| 175 | + - name: Verify that the output is correct |
| 176 | + working-directory: ${{ matrix.workdir }} |
| 177 | + run: | |
| 178 | + if grep -q "${{ matrix.expected }}" "${{ matrix.files }}.out"; then |
| 179 | + echo "Output matches" |
| 180 | + else |
| 181 | + echo "Output mismatch. Expected something matching '${{ matrix.expected }}'. Got the following:" |
| 182 | + cat "${{ matrix.files }}.out" |
| 183 | + exit 1 |
| 184 | + fi |
0 commit comments