solidity icon indicating copy to clipboard operation
solidity copied to clipboard

assertion failed [block != nullptr]: BasicBlock requested for unrecognized address (BuilderBase.h:550 block_for_offset)

Open Qambar opened this issue 2 years ago • 2 comments

Description

The compiler is crashing with the following error message:

$ yarn test
yarn run v1.22.10
$ npx hardhat compile; truffle test --network local
Solidity 0.8.17 is not fully supported yet. You can still use Hardhat, but some features, like stack traces, might not work correctly.

Learn more at https://hardhat.org/hardhat-runner/docs/reference/solidity-support

Nothing to compile
Using network 'local'.


Compiling your contracts...
===========================
assertion failed [block != nullptr]: BasicBlock requested for unrecognized address
(BuilderBase.h:550 block_for_offset)
/bin/sh: line 1: 12129 Trace/BPT trap: 5       truffle test --network local
error Command failed with exit code 133.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I contacted truffle support, and they advised that it was a compiler bug and it should be reported here.

Environment

  • Compiler version: Truffle v5.4.11 (core: 5.4.11) Solidity - 0.8.17 (solc-js) Node v18.7.0 Web3.js v1.5.2

  • Target EVM version (as per compiler settings): 0.8.17

  • Framework/IDE (e.g. Truffle or Remix): 5.4.11

  • EVM execution environment / backend / blockchain client: ganache v7.4.1 (@ganache/cli: 0.5.1, @ganache/core: 0.5.1)

  • Operating system: Mac OS

Steps to Reproduce

This error is intermittent, I will record a video to demonstrate it and share it in the comments. Also, documenting the steps below

  1. Run truffle test
$ yarn test
yarn run v1.22.10
$ npx hardhat compile; truffle test --network local
  1. It will compile contracts
Nothing to compile
Using network 'local'.


Compiling your contracts...
===========================
assertion failed [block != nullptr]: BasicBlock requested for unrecognized address
(BuilderBase.h:550 block_for_offset)
/bin/sh: line 1: 12129 Trace/BPT trap: 5       truffle test --network local
error Command failed with exit code 133.
  1. Run the truffle test again and it might work
$ yarn test
yarn run v1.22.10
$ npx hardhat compile; truffle test --network local
Solidity 0.8.17 is not fully supported yet. You can still use Hardhat, but some features, like stack traces, might not work correctly.

Learn more at https://hardhat.org/hardhat-runner/docs/reference/solidity-support

Nothing to compile
Using network 'local'.


Compiling your contracts...
===========================
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/TheAgencyPassContract.sol
> Artifacts written to /var/folders/f_/ll33dc315ldc738pbth9339m0000gp/T/test--12086-Y5KWaRC2tIAx
> Compiled successfully using:
   - solc: 0.8.17+commit.8df45f5f.Emscripten.clang
Your contract is deployed to 0xb2139Df9e18a07AeEA394FE9B70ACDD89e6A0474


  Testing contract
    ✔ can run tests
    ✔ contract has royalty equal to 10%
    ✔ should have the max supply of 450
    ✔ Should be able to mint reserved (74ms)
    ✔ Should start at token id 1 (92ms)
    ✔ Should be able to mint reserved 11 items (63ms)
    ✔ Should not be able to mint whitelist if sale is not active  (86ms)
    ✔ Should be able to mint whitelist (109ms)
    ✔ Should be able to mint OG whitelist
    ✔ Should be able to mint OG whitelist (124ms)
    ✔ Should be not able to mint twice OG whitelist (76ms)
    ✔ Should send royalty back to the contract


  12 passing (5s)

✨  Done in 16.35s.

Qambar avatar Sep 14 '22 05:09 Qambar

Is that error really coming from the compiler? We do have a struct called BasicBlock but no BuilderBase.h (it's part of the control flow graph instead).

If it's a compiler problem it should be reproducible just by running solc (or solc-js) on it without Truffle or Hardhat. Can you show us the input contracts? Or preferably some minimal piece of code needed to trigger this?

cameel avatar Sep 14 '22 14:09 cameel

Same for me:

assertion failed [block != nullptr]: BasicBlock requested for unrecognized address (BuilderBase.h:550 block_for_offset)

And also on MacOs. Same code on Ubuntu works.

pavbro avatar Sep 15 '22 17:09 pavbro

This error happens running Deno scripts on macos with M1. It's nothing to do with solidity per se.

crucialfelix avatar Oct 19 '22 14:10 crucialfelix

Thanks for confirming @crucialfelix.

In that case I'm going to close this.

cameel avatar Oct 19 '22 15:10 cameel

Solved

The issue

For those who find this and are still stuck with these intermittent errors. The issue (that I had) was that node was installed with x86 arch on an M2 Mac. The underlying issue is with Rosetta, which is used to translate between the x86 instructions to Apple silicon.

I encountered this particular problem where the integrated terminal in VSCode kept using Rosetta as the default option.

You can check the arch in your terminal.

$ node -e 'console.log(process.arch)'
// That will probably output x86

$ arch
// This will probably output i386

Steps to solve

If you're using brew, delete node entirely and install nvm

  • open up terminal (I use iTerm)
  • Run arch and make sure it's arm64
  • Switch to a different version of node (install it if you have to)
    • nvm install [OTHER VERSION OF NODE]
    • nvm use [OTHER VERSION OF NODE]
  • remove the previously used version of node
    • nvm uninstall [VERSION OF NODE YOU WANT]
    • nvm install [VERSION OF NODE YOU WANT]
    • nvm use [VERSION OF NODE YOU WANT]
    • nvm alias default [VERSION OF NODE YOU WANT]
  • open a new terminal window and check to make sure node -v returns the correct node version
  • check the output of node -e 'console.log(process.arch)'
    • it should now be arm64
  • don't forget to npm i -g truffle and any other global packages you use
  • ????
  • PROFIT

Steps to solve in VSCode

Add this into your settings.json

  "terminal.integrated.profiles.osx": {
    "bash": {
      "path": "arch",
      "args": ["-arm64", "bash", "-l"],
      "overrideName": true
    }
  },
  "terminal.integrated.defaultProfile.osx": "bash"

Thanks for listening to my TED Talk

notVitaliy avatar May 11 '23 20:05 notVitaliy

You can also run brew commands this way:

arch -arm64 brew upgrade

crucialfelix avatar May 13 '23 06:05 crucialfelix

If you have cpu m1/m2 y can use nodenv to install node with version you need. So, i made patch inside nodenv builder or inside bash script /usr/local/bin/node-build in the platform detector method:

#  arch="$(uname -m)"
  arch="arm64"

it work like a charm. compilation speed increased in 70% or more.

To install some special vesrion:

nodenv install 18.16.0
nodenv local 18.16.0

pashuka avatar May 07 '24 16:05 pashuka