0

I am going through brownie_fund_me part of this course:

https://github.com/PatrickAlphaC/brownie_fund_me

The initial deploy,.py works properly, but I keep getting some variation of invalid opcode and the transaction keeps reverting when I try to deploy to ganache-local. I am able to run the tests in this project to development/ganache-cli but fail with ganache-local and Rinkeby.

Expected Behavior

Contract should deploy fund and withdraw properly with Ganache UI.

Current Behavior

Running `brownie run deploy.py --network ganache-local. I get these errors while running or troubleshooting.

  • ValueError: Gas estimation failed: 'execution reverted: VM Exception while processing transaction: invalid opcode'. This transaction will likely revert. If you wish to broadcast, you must set the gas limit manually.
  • ValueError: Execution reverted during call: 'execution reverted: VM Exception while processing transaction: invalid opcode'. This transaction will likely revert. If you wish to broadcast, include allow_revert:True as a transaction parameter.
  • VirtualMachineError: invalid opcode: invalid opcode

Steps to reproduce & Troubleshooting

  1. Git clone https://github.com/PatrickAlphaC/brownie_fund_me

  2. brownie compile -a. Compiles successfully.

  Solc version: 0.6.12
  Optimizer: Enabled  Runs: 200
  EVM Version: Istanbul
Generating build data...
 - smartcontractkit/chainlink-brownie-contracts@1.1.1/AggregatorInterface
 - smartcontractkit/chainlink-brownie-contracts@1.1.1/AggregatorV2V3Interface
 - smartcontractkit/chainlink-brownie-contracts@1.1.1/AggregatorV3Interface
 - smartcontractkit/chainlink-brownie-contracts@1.1.1/SafeMathChainlink
 - FundMe
 - MockV3Aggregator
 Project has been compiled. Build artifacts saved at /Users/davidandrews/Documents/Projects/Web3/bss/build/contracts
  1. Deploy ganache ui with default gas limit and values.
  2. Execute brownie run scripts/deploy.py --network ganache-local
 ~/Documents/Projects/Web3/brownie_fund_me (main●●)$ brownie run scripts/deploy.py --network ganache-local 
Brownie v1.17.1 - Python development framework for Ethereum

brownie_fund_me is the active project.

Running 'scripts/deploy.py::main'...
The active network is ganache-local
Deploying Mocks...
Transaction sent: 0xe7b501480f70836256dbdd37a159100198d1422897117777e33588d1b2e1a566
  Gas price: 20.0 gwei   Gas limit: 540226   Nonce: 0
  MockV3Aggregator.constructor confirmed   Block: 1   Gas used: 491115 (90.91%)
  MockV3Aggregator deployed at: 0xF5F2B13A72901f1621d2CD9b382c1c513ac0724D

Mocks Deployed!
Transaction sent: 0xc5a26f42997e9c648ee4d12df1805746cd3ca6508c315747f9b836ce5fb39516
  Gas price: 20.0 gwei   Gas limit: 528696   Nonce: 1
  FundMe.constructor confirmed   Block: 2   Gas used: 480633 (90.91%)
  FundMe deployed at: 0xEDa314a434Ef759d85F60a54804FdfdbEB26F179

Contract deployed to 0xEDa314a434Ef759d85F60a54804FdfdbEB26F179
  1. Execute: brownie run scripts/fund_and_withdraw.py --network ganache-local

BssProject is the active project.

Running 'scripts/fund_and_withdraw.py::main'...
25000000000000000
The current entry fee is 25000000000000000
Funding
Transaction sent: 0xffd686e74b439f0afff97ba5ab77ce31a48a66a6f2710d123b3cf37bc8b8bade
  Gas price: 20.0 gwei   Gas limit: 94207   Nonce: 2
  FundMe.fund confirmed   Block: 3   Gas used: 85643 (90.91%)

  File "brownie/_cli/run.py", line 50, in main
    return_value, frame = run(
  File "brownie/project/scripts.py", line 103, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File "./scripts/fund_and_withdraw.py", line 23, in main
    withdraw()
  File "./scripts/fund_and_withdraw.py", line 18, in withdraw
    fund_me.withdraw({"from": account})
  File "brownie/network/contract.py", line 1625, in __call__
    return self.transact(*args)
  File "brownie/network/contract.py", line 1498, in transact
    return tx["from"].transfer(
  File "brownie/network/account.py", line 644, in transfer
    receipt, exc = self._make_transaction(
  File "brownie/network/account.py", line 727, in _make_transaction
    raise VirtualMachineError(e) from None
  File "brownie/exceptions.py", line 121, in __init__
    raise ValueError(str(exc)) from None
ValueError: Gas estimation failed: 'execution reverted: VM Exception while processing transaction: invalid opcode'. This transaction will likely revert. If you wish to broadcast, you must set the gas limit manually.
  1. Change gas_limit param to default Ganache UI gas_limit: fund_me.withdraw({"from": account}) -> fund_me.withdraw({"from": account, 'gas_limit': 6721975}) and run fund_and_withdraw.py.
Brownie v1.17.1 - Python development framework for Ethereum

BssProject is the active project.

Running 'scripts/fund_and_withdraw.py::main'...
25000000000000000
The current entry fee is 25000000000000000
Funding
Transaction sent: 0x996f97219b9c8cf1dd3f88753adf4c94335d27d1784972b976c550cea5f13c6d
  Gas price: 20.0 gwei   Gas limit: 61207   Nonce: 3
  FundMe.fund confirmed   Block: 4   Gas used: 55643 (90.91%)

  File "brownie/_cli/run.py", line 50, in main
    return_value, frame = run(
  File "brownie/project/scripts.py", line 103, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File "./scripts/fund_and_withdraw.py", line 24, in main
    withdraw()
  File "./scripts/fund_and_withdraw.py", line 19, in withdraw
    fund_me.withdraw({"from": account, 'gas_limit': 6721975})
  File "brownie/network/contract.py", line 1625, in __call__
    return self.transact(*args)
  File "brownie/network/contract.py", line 1498, in transact
    return tx["from"].transfer(
  File "brownie/network/account.py", line 644, in transfer
    receipt, exc = self._make_transaction(
  File "brownie/network/account.py", line 752, in _make_transaction
    exc = VirtualMachineError(e)
  File "brownie/exceptions.py", line 121, in __init__
    raise ValueError(str(exc)) from None
ValueError: Execution reverted during call: 'execution reverted: VM Exception while processing transaction: invalid opcode'. This transaction will likely revert. If you wish to broadcast, include `allow_revert:True` as a transaction parameter.
  1. Added fund_me.withdraw({"from": account, 'gas_limit': 6721975, 'allow_revert': True})
Brownie v1.17.1 - Python development framework for Ethereum

BrownieFundMeProject is the active project.

Running 'scripts/fund_and_withdraw.py::main'...
25000000000000000
The current entry fee is 25000000000000000
Funding
Transaction sent: 0x1709a9bb9cf6213526c0307eb01c91c00a644a227c8a0efffa71310f3b94a106
  Gas price: 20.0 gwei   Gas limit: 61207   Nonce: 4
  FundMe.fund confirmed   Block: 5   Gas used: 55643 (90.91%)

  FundMe.fund confirmed   Block: 5   Gas used: 55643 (90.91%)

Transaction sent: 0x5e4947dc2d642dbb337eefdb6711c33b39eca70e2294aed10c05e3d15861b3a2
  Gas price: 20.0 gwei   Gas limit: 6721975   Nonce: 5
  FundMe.withdraw confirmed (invalid opcode)   Block: 6   Gas used: 6721975 (100.00%)

  File "brownie/_cli/run.py", line 50, in main
    return_value, frame = run(
  File "brownie/project/scripts.py", line 103, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File "./scripts/fund_and_withdraw.py", line 28, in main
    withdraw()
  File "./scripts/fund_and_withdraw.py", line 21, in withdraw
    tx = fund_me.withdraw({"from": account, 'gas_limit': 6721975, 'allow_revert': True})
  File "brownie/network/contract.py", line 1625, in __call__
    return self.transact(*args)
  File "brownie/network/contract.py", line 1498, in transact
    return tx["from"].transfer(
  File "brownie/network/account.py", line 682, in transfer
    receipt._raise_if_reverted(exc)
  File "brownie/network/transaction.py", line 446, in _raise_if_reverted
    raise exc._with_attr(
VirtualMachineError: invalid opcode: invalid opcode
  1. I am also deleting build artifacts between runs.
  2. I've tried this:
  • delete ganache-local from your brownie networks list

  • delete the corresponding folders on build/deployments/1337(or whatever your chainID was) as well as the corresponding chainid lines of the map.json file

  • on your Ganache instance, instead of clicking on the quicklaunch, click on create workspace

  • Set up the gas limit to a higher number than it is currently at (I chose 8000000), the rest can stay as it is

  • on your VSC terminal, or whatever program you use to type your code, re-introduce the network ganache-local (brownie networks add Ethereum ganache-local host=http://YOURHOSTNUMBER chainid=YOURCHAINID

I've tried setting the gas_limit in ganache ui to 999999999999999 and gas price to gwei.

Possible Solution

This appears to be a gas estimation and gas price issue with Ganache UI.

Context

I'm trying to complete this course: https://github.com/smartcontractkit/full-blockchain-solidity-course-py#lesson-6-brownie-fund-me

Your Environment

  • Python 3.9.8
  • Ganache version: Ganache CLI v6.12.2 (ganache-core: 2.13.2) RPC Server: HTTP://127.0.0.1:7545 chainid=1377
  • Ganache UI version: Version 2.5.4 (2.5.4.1367)
  • Node version: v16.8.0
  • Operating System and version: macOS Monterey 12.1 Beta
  • Truffle version: Truffle v5.4.21
  • Link to your project: https://github.com/PatrickAlphaC/brownie_fund_me. I've cloned this repo to make sure I didn't have a bug in my own code.
2
  • From the error message it doesn't seem to be an issue with the gas but the contract is reverting for some other reason.
    – Ismael
    Dec 4, 2021 at 20:43
  • I encountered the same error too. When I ran getPrice() on the FundMe contract, the answer returned was 200000000000,0000000000,0000000000. Not sure how to fix this.
    – shonendumm
    Dec 18, 2021 at 4:30

2 Answers 2

2

getPrice() isn't returning a number you want from the mock, somewhere in the vicinity of 2B. Think this is a bug with the Ganache implementation- performing the calculation (minimumUSD * precision) / price in getEntranceFee() gives you a number less than 1- and, since Solidity can't handle floats, Solidity simply sees it as a 0, and the whole thing errors out.

0

The problem seems to be related to the version of Ganache: If you use the ganache GUI, you get the miscalculation regarding the entree fee and gas estimation error. If you start the ganache-cli locally, in another window, it works, both the calculation and the call of withdraw() :

ganache-cli --accounts 10 --hardfork istanbul --gasPrice 2000000000 --gasLimit 6721975 --mnemonic brownie --port 8545

I am using ganache@7.0.3 installed from npm -g install ganache

It works also if you start hardhat node in another window, with the following definition in hardhat-config.js :

networks: { hardhat: { initialBaseFeePerGas: 0, accounts: { mnemonic: "test test test test test test test test test test test junk", path: "m/44'/60'/0'/0", count: 10, accountsBalance: "100000000000000000000", }, }, }

BrownieFundMeProject is the active project.

Running 'scripts/fund_and_withdraw.py::main'... 25000000000000001 The current entry fee is 25000000000000001 Funding Transaction sent: >0xcd8f0db14647958c4902dcce05b2baf41f1a6604999867f4bd726df02273dc68 Gas price: 2.0 gwei Gas limit: 99258 Nonce: 5 FundMe.fund confirmed Block: 6 Gas used: 90235 (90.91%)

Transaction sent: >0xab399fb117adac26e2a381e6fab907880a1bc796d64a26f6f7915925fd6b90d5 Gas price: 2.0 gwei Gas limit: 76963 Nonce: 6 FundMe.withdraw confirmed Block: 7 Gas used: 24967 (32.44%)

So it looks like a bug in Ganache GUI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.