coinspect / learn-evm-attacks

Learn and contribute by exploring blockchain attacks in detail. Maintained by Coinspect smart contract audit team, renowned for their top-tier smart contract audit services.
https://www.coinspect.com/services/smart-contract-audit/
MIT License
1.67k stars 215 forks source link

Unable to execute `Exploit_MBCToken` test #54

Closed grGred closed 1 year ago

grGred commented 1 year ago

After executing:

$ git clone https://github.com/coinspect/learn-evm-attacks
$ forge install
$ forge test --match-contract Exploit_MBCToken -vvv

I recieved a lot of errors and was unable to complie the contract:

...
Discovered incompatible solidity versions in following
: test\Reentrancy\RevestFinance\RevestFinance.attack.sol (^0.8.17) imports:
    lib/forge-std/src\Test.sol (>=0.6.2 <0.9.0)
    test\TestHarness.sol (^0.8.17)
    test\interfaces\IERC20.sol (^0.8.0)
...

I've added solc="0.8.17" to foundry.toml, contracts compiled, and I received new error (the same as other 2 people):

forge test --match-contract Exploit_MBCToken
[⠢] Compiling...
No files changed, compilation skipped
The application panicked (crashed).
Message:  Failed to get account for 0x55d3…7955
(code: -32002, message: the resource eth_getCode is not available., data: None)
Location: evm/src/executor/fork/backend.rs:271

This is a bug. Consider reporting it at https://github.com/foundry-rs/foundry

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
Aborted

This looks loke the problem with the rpc, could you please check that?

joaquinlpereyra commented 1 year ago

Thanks for filling @grGred. I can't reproduce:

$ forge test --match-contract Exploit_MBCToken # running with no -vvv so as to not clutter output
[⠰] Compiling...
No files changed, compilation skipped

Running 1 test for test/Access_Control/MBCToken/MBCToken.attack.sol:Exploit_MBCToken
[PASS] test_attack() (gas: 2414975)
Test result: ok. 1 passed; 0 failed; finished in 696.86ms

This usually does indicate an issue with the RPC though:

Message:  Failed to get account for 0x55d3…7955

We use Ankr's free RPC as default. It might fail sometimes (specially considering it's a free tier). You are free to customize it for the one of your preference or try another one if it fails (see foundry.toml)

Try again and let me know if the issue persists. I will close the issue for now pending your answer.

This might need to go to the README in a troubleshooting section though so I will work on that.

grGred commented 1 year ago

Okay, but you still should lock comilper version in foundry.toml for 0.8.17. Since users localy can have other version of solc in use, which may lead to failed execution of tests. By the way thanks for you work!