Home

Awesome

Echidna action

This action allows you to run echidna-test from within a GitHub Actions workflow. The action builds on the trailofbits/echidna Docker image, adding solc-select and providing a simpler way to execute Echidna as part of an Actions workflow.

To learn more about Echidna itself, visit its GitHub repository and wiki pages.

Inputs

KeyDescription
filesRequired Solidity files or folders to analyze.
contractContract to analyze.
configConfig file (CLI arguments override config options).
formatOutput format: json, text, none. Disables interactive UI.
corpus-dirDirectory to store corpus and coverage data.
test-modeType of tests to be performed: property, assertion, overflow, optimization, exploration.
multi-abiUse multi-abi mode of testing.
test-limitNumber of sequences of transactions to generate during testing.
shrink-limitNumber of tries to attempt to shrink a failing sequence of transactions.
seq-lenNumber of transactions to generate during testing.
contract-addrAddress to deploy the contract to test.
deployerAddress of the deployer of the contract to test.
senderAddresses to use for the transactions sent during testing.
seedRun with a specific seed.
crytic-argsAdditional arguments to use in crytic-compile for the compilation of the contract to test.
solc-argsAdditional arguments to use in solc for the compilation of the contract to test.
solc-versionVersion of the Solidity compiler to use.
output-fileCapture echidna-test's output into a file. The path must be relative to the repository root.
echidna-versionVersion of the Echidna Docker image to use.
negate-exit-statusApply logical NOT to echidna-test's exit status (for testing the action).
echidna-workdirPath to run echidna-test from. Note that files and config are relative to this path.

Outputs

KeyDescription
output-fileIf produced, the file containing echidna-test's output, relative to the repository root.

Examples

Basic usage

uses: crytic/echidna-action@v2
with:
  files: contracts/
  contract: Marketplace

Example workflow: Hardhat

The following is a complete GitHub Actions workflow example. It will trigger with commits on master as well as any pull request opened against the master branch. It will configure NodeJS 16.x on the runner, and then install project dependencies (using npm ci). Once the environment is set up, it will build the project (using npx hardhat compile) and finally run Echidna against a contract called TokenEchidna. The workflow will fail if Echidna breaks any of the invariants in TokenEchidna.

In this example, we are leveraging crytic-args to pass --hardhat-ignore-compile. This skips building the project as part of the Echidna action, and instead takes advantage of the already built contracts. This is required, as the Echidna action environment does not have NodeJS available.

name: Echidna Test

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v3
    - name: Use Node.js 16
      uses: actions/setup-node@v2
      with:
        node-version: 16
        cache: 'npm'
    - name: Install dependencies
      run: npm ci
    - name: Compile contracts
      run: npx hardhat compile
    - name: Run Echidna
      uses: crytic/echidna-action@v2
      with:
        solc-version: 0.7.6
        files: .
        contract: TokenEchidna
        crytic-args: --hardhat-ignore-compile

Example workflow: Foundry

The following is a complete GitHub Actions workflow example. It will trigger with commits on main as well as any pull request opened against the main branch. It will install Foundry on the runner, and then it will build the project (using forge build --build-info) and finally run Echidna against a contract called TokenEchidna. The workflow will fail if Echidna breaks any of the invariants in TokenEchidna.

In this example, we are leveraging crytic-args to pass --ignore-compile. This skips building the project as part of the Echidna action, and instead takes advantage of the already built contracts. This is required, as the Echidna action environment does not have forge available.

name: Echidna Test

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

env:
  FOUNDRY_PROFILE: ci

jobs:
  test:      
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v3
      with:
        submodules: recursive

    - name: Install Foundry
      uses: foundry-rs/foundry-toolchain@v1
      with:
        version: nightly

    - name: Compile contracts
      run: |
        forge build --build-info

    - name: Run Echidna
      uses: crytic/echidna-action@v2
      with:
        files: .
        contract: TokenEchidna
        crytic-args: --ignore-compile