echidna icon indicating copy to clipboard operation
echidna copied to clipboard

Given contract not found in given file

Open mgayanov opened this issue 2 years ago • 4 comments

Hello!

Fuzzing contracts from damn-vulnerable-defi-echidna fails with message Given contract not found in given file, if there is any invalid contract in project.

To reproduce:

Project are clean, fuzzing works:

$ cd damn-vulnerable-defi-echidna && \
echidna-test_v2.0.5 . --contract NaiveReceiverEchidna --config naivereceiver.yaml

echidna_test_contract_balance: failed!💥  
  Call sequence:
    flashLoan(0x62d69f6867a0a084c6d313943dc22023bc263691,33)

Add invalid contract at contracts/unstoppable/123.sol:

pragma solidity ^0.8.0;

contract UnstoppableEchidna {

    constructor() payable {
        123
    }

}

And run fuzzer again:

$ echidna-test_v2.0.5 . --contract NaiveReceiverEchidna --config naivereceiver.yaml

echidna-test_v2.0.5: Given contract "NaiveReceiverEchidna" not found in given file

Remove contracts/unstoppable/123.sol and run again:

$ rm contracts/unstoppable/123.sol && \
echidna-test_v2.0.5 . --contract NaiveReceiverEchidna --config naivereceiver.yaml

echidna_test_contract_balance: failed!💥  
  Call sequence:
    flashLoan(0x62d69f6867a0a084c6d313943dc22023bc263691,4369999)

mgayanov avatar Feb 01 '23 11:02 mgayanov

Add invalid contract at contracts/unstoppable/123.sol

We don't support compilations that are invalid. If this happens by accident it should warn it, but in general, you should be doing this.

gustavo-grieco avatar Mar 12 '23 11:03 gustavo-grieco

Hello,

I am experiencing this same error while trying to run Echidna on a Foundry project on the CI, although I don't have any invalid contracts, since I can compile without issues, and can run on local without issues.

My ci.yaml is

  invariants:
    strategy:
      matrix:
        mode: [assertion, property]

    name: Echidna
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive

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

      - name: Install Crytic-compile
        run: |
          pip install crytic-compile

      - name: Install Echidna
        run: |
          wget https://github.com/crytic/echidna/releases/download/v2.2.1/echidna-2.2.1-Linux.zip -O echidna.zip
          unzip echidna.zip
          tar -xvkf echidna.tar.gz
          rm echidna.zip echidna.tar.gz
          ./echidna --version

      - name: Echidna ${{ matrix.mode }}
        run: |
          ./echidna . --contract CryticTester --config echidna.yaml --test-mode ${{ matrix.mode }} --test-limit 100000 --corpus-dir corpus

Do you have any ideas of what's wrong?

aviggiano avatar Jan 24 '24 13:01 aviggiano

Hi @aviggiano, is your CryticTester contract on Foundry's test or script directory by any chance? I believe crytic-compile skips building those to improve compilation speeds.

elopez avatar Jan 24 '24 14:01 elopez

Hi @aviggiano, is your CryticTester contract on Foundry's test or script directory by any chance? I believe crytic-compile skips building those to improve compilation speeds.

Yes, that was the issue, thank you for the answer.

aviggiano avatar Jan 24 '24 15:01 aviggiano

It seems this is already fixed. Closing it.

gustavo-grieco avatar May 08 '24 17:05 gustavo-grieco