eth-brownie / brownie

A Python-based development and testing framework for smart contracts targeting the Ethereum Virtual Machine.
https://eth-brownie.readthedocs.io
MIT License
2.64k stars 550 forks source link

Cannot compile contract with block.basefee #1467

Open BlinkyStitt opened 2 years ago

BlinkyStitt commented 2 years ago

Environment information

What was wrong?

>>> c = Contract.from_explorer("0xca11bde05977b3631167028862be2a173976ca11")
Fetching source of 0xcA11bde05977b3631167028862bE2a173976CA11 from api.etherscan.io...
CompilerError: solc returned the following errors:

TypeError: "basefee" is not supported by the VM version.
   --> Multicall3-flattened.sol:209:19:
    |
209 |         basefee = block.basefee;
    |                   ^^^^^^^^^^^^^

>>> CONFIG.settings['compiler']['evm_version']
'london'

How can it be fixed?

I don't know. Is my compiler version not getting passed through to from_explorer?

sandybradley commented 2 years ago

Same issue:

$ brownie compile
Brownie v1.19.1 - Python development framework for Ethereum

Compiling contracts...
  Solc version: 0.8.16
  Optimizer: Enabled  Runs: 200
  EVM Version: Istanbul
CompilerError: solc returned the following errors:

TypeError: "basefee" is not supported by the VM version.

Error message from: https://github.com/ethereum/solidity/blob/2ddb26ad96e851e55c57c90d4841967717db4eb8/libsolidity/analysis/TypeChecker.cpp#L3299

BlinkyStitt commented 2 years ago

Same issue:

$ brownie compile
Brownie v1.19.1 - Python development framework for Ethereum

Compiling contracts...
  Solc version: 0.8.16
  Optimizer: Enabled  Runs: 200
  EVM Version: Istanbul
CompilerError: solc returned the following errors:

TypeError: "basefee" is not supported by the VM version.

Error message from: https://github.com/ethereum/solidity/blob/2ddb26ad96e851e55c57c90d4841967717db4eb8/libsolidity/analysis/TypeChecker.cpp#L3299

Looks like you are set to Istanbul. Can you set your hard fork to London (or later) and try again?

sandybradley commented 2 years ago

Yes, that worked, thank you.

compiler:
    evm_version: london
    solc:
        version: 0.8.16
        optimizer:
            enabled: true
            runs: 20000
        remappings: null
chhajershrenik commented 1 year ago

The same issue persists when using module Contract.from_explorer, when writing tests. How do I change the VM version in input_json for imported contracts.

image

For testing I'm importing the Entry point contract from the mainnet "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789".

chhajershrenik commented 1 year ago

The same issue persists when using module Contract.from_explorer, when writing tests. How do I change the VM version in input_json for imported contracts.

image

For testing I'm importing the Entry point contract from the mainnet "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789".

My brownie config:

project_structure:
  build: brownie-build
networks:
  default: mainnet-fork
  mainnet-fork:
    verify: True
    cmd_settings:
      accounts: 20
      account_keys_path: "ganacheaccount.json"
      evm_version: "london"
autofetch_sources: True
dependencies:
  - OpenZeppelin/openzeppelin-contracts@4.8.3
  - uniswap/v3-core@1.0.0
  - uniswap/v2-core@1.0.1
  - uniswap/v3-periphery@1.3.0
  - uniswap/v2-periphery@1.0.0-beta.0
  - smartcontractkit/chainlink@2.1.1
  - uniswap/v2-periphery@1.0.0-beta.0
compiler:
  evm_version: "london"
  solc:
    optimizer:
      enabled: true
      runs: 20000
    remappings:
      - '@openzeppelin=OpenZeppelin/openzeppelin-contracts@4.8.3'
      - '@uniswap/v3-core=uniswap/v3-core@1.0.0'
      - '@uniswap/v2-core=uniswap/v2-core@1.0.1'
      - '@uniswap/v3-periphery=uniswap/v3-periphery@1.3.0'
      - '@uniswap/v2-periphery=uniswap/v2-periphery@1.0.0-beta.0'
      - '@chainlink=smartcontractkit/chainlink@2.1.1'