NomicFoundation / edr

An Ethereum development runtime implementation that can be reused to build new developer tools.
MIT License
57 stars 12 forks source link

smock.fake makes EDR panic #400

Closed EdNoepel closed 6 months ago

EdNoepel commented 6 months ago

I am updating from Hardhat 2.16.1 to 2.22.3 to gain Cancun support. My contracts compile and generate types, and I can run simple unit tests. However, when I try to run a test that deploys a complicated contract, the EDR (version 0.3.5) encounters a fatal error, ending the process.

Using node v18.13.0. Some package versions:

$ yarn list --depth=0 | grep hardhat
├─ @nomicfoundation/hardhat-chai-matchers@1.0.6
├─ @nomicfoundation/hardhat-network-helpers@1.0.10
├─ @nomicfoundation/hardhat-toolbox@2.0.2
├─ @nomicfoundation/hardhat-verify@2.0.6
├─ @nomiclabs/hardhat-ethers@2.2.3
├─ @nomiclabs/hardhat-etherscan@3.1.8
├─ @typechain/hardhat@6.1.6
├─ hardhat-contract-sizer@2.10.0
├─ hardhat-dependency-compiler@1.1.4
├─ hardhat-deploy@0.12.2
├─ hardhat-gas-reporter@2.1.1
├─ hardhat@2.22.3
$ yarn list --depth=0 | grep edr
├─ @nomicfoundation/edr-darwin-arm64@0.3.5
├─ @nomicfoundation/edr-darwin-x64@0.3.5
├─ @nomicfoundation/edr-linux-arm64-gnu@0.3.5
├─ @nomicfoundation/edr-linux-arm64-musl@0.3.5
├─ @nomicfoundation/edr-linux-x64-gnu@0.3.5
├─ @nomicfoundation/edr-linux-x64-musl@0.3.5
├─ @nomicfoundation/edr-win32-x64-msvc@0.3.5
├─ @nomicfoundation/edr@0.3.5

With backtrace enabled, here's what I get on linux:

FATAL ERROR: threadsafe_function.rs:749 Failed to convert return value in ThreadsafeFunction callback into Rust value: InvalidArg, Missing field `result`
thread 'tokio-runtime-worker' panicked at crates/edr_napi/src/call_override.rs:103:14:
called `Result::unwrap()` on an `Err` value: RecvError
stack backtrace:
 1: 0xb6b850 node::Abort() [node]
 2: 0xa805b2 node::FatalError(char const*, char const*) [node]
 3: 0xa805bb node::OOMErrorHandler(char const*, bool) [node]
 4: 0xb31613 napi_fatal_error [node]
 5: 0x7feadc8dfc99  [/[PROJECT_DIR]/node_modules/@nomicfoundation/edr-linux-x64-gnu/edr.linux-x64-gnu.node]
 6: 0xb2cc3a  [node]
 7: 0x1652906  [node]
 8: 0x1664e44  [node]
 9: 0x165326e uv_run [node]
10: 0xaafa2d node::SpinEventLoop(node::Environment*) [node]
11: 0xbb11f4 node::NodeMainInstance::Run() [node]
12: 0xb26c44 node::LoadSnapshotDataAndRun(node::SnapshotData const**, node::InitializationResult const*) [node]
13: 0xb2a83f node::Start(int, char**) [node]
14: 0x7feaf495ed90  [/lib/x86_64-linux-gnu/libc.so.6]
15: 0x7feaf495ee40 __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6]
16: 0xaad7ee _start [node]
Aborted (core dumped)

Similar callstack run from a mac:

thread 'FATAL ERROR: threadsafe_function.rs:749 Failed to convert return value in ThreadsafeFunction callback into Rust value: InvalidArg, Missing field `result`
tokio-runtime-worker' panicked at crates/edr_napi/src/call_override.rs:103:14:
called `Result::unwrap()` on an `Err` value: RecvError
stack backtrace:
 1: 0x100b79f80 node::Abort() [/[ASDF_INSTALLS]/nodejs/18.19.0/bin/node]
 2: 0x100b7a06c node::OOMErrorHandler(char const*, bool) [/[ASDF_INSTALLS]/nodejs/18.19.0/bin/node]
 3: 0x100b48908 napi_open_callback_scope [/[ASDF_INSTALLS]/nodejs/18.19.0/bin/node]
 4: 0x11ccc5d8c  [/[PROJECT_DIR]/node_modules/@nomicfoundation/edr-darwin-arm64/edr.darwin-arm64.node]
 5: 0x100b4b9e0 v8impl::(anonymous namespace)::ThreadSafeFunction::AsyncCb(uv_async_s*) [/[ASDF_INSTALLS]/nodejs/18.19.0/bin/node]
 6: 0x1014ac744 uv__async_io [/[ASDF_INSTALLS]/nodejs/18.19.0/bin/node]
 7: 0x1014becf8 uv__io_poll [/[ASDF_INSTALLS]/nodejs/18.19.0/bin/node]
 8: 0x1014acc14 uv_run [/[ASDF_INSTALLS]/nodejs/18.19.0/bin/node]
 9: 0x100abd6e0 node::SpinEventLoop(node::Environment*) [/[ASDF_INSTALLS]/nodejs/18.19.0/bin/node]
10: 0x100bb64fc node::NodeMainInstance::Run() [/[ASDF_INSTALLS]/nodejs/18.19.0/bin/node]
11: 0x100b46490 node::LoadSnapshotDataAndRun(node::SnapshotData const**, node::InitializationResult const*) [/[ASDF_INSTALLS]/nodejs/18.19.0/bin/node]
12: 0x100b46748 node::Start(int, char**) [/[ASDF_INSTALLS]/nodejs/18.19.0/bin/node]
13: 0x1852f60e0 start [/usr/lib/dyld]
error Command failed with signal "SIGABRT".

Any guidance would be appreciated. Unsure how to reproduce this with a simple example.

EdNoepel commented 6 months ago

Suspect it may be some incompatibility with @defi-wonderland/smock@2.4.0, which purports to support EDR versions of hardhat.

EdNoepel commented 6 months ago

Was able to reproduce a very similar crash in this example: https://github.com/EdNoepel/edr-crash-repro

fvictorio commented 6 months ago

Thank you @EdNoepel! We'll look into this.

fvictorio commented 6 months ago

Confirmed. Here's a slightly more minimal example: https://github.com/fvictorio/edr-smock-issue

Wodann commented 6 months ago

We fixed the issue and will release a patch version of EDR soon.

agostbiro commented 5 months ago

We've released EDR v0.3.8 with a fix for this issue.

To upgrade to the latest EDR version immediately, you can remove your node_modules directory and npm/yarn/pnpm lock file and reinstall your dependencies. Otherwise you can wait for the next Hardhat release which will automatically use the latest EDR version.

You can verify that you’re using the latest version of EDR by running the following command: npm ls @nomicfoundation/edr.