Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Deploying ganache-local w/brownie: VM Exception while processing transaction: invalid opcode #6

Closed
GratefulDave opened this issue Nov 22, 2021 · 12 comments

Comments

@GratefulDave
Copy link

Thanks for an amazing class Patrick. I taught myself to code 3 years ago and wish I did it 33 years ago! :)

Issue

I am going through brownie simple storage part of this course. The initial deploy,.py works properly, but I keeping getting some variation of invalid opcode and the transaction is 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.

I am experiencing the same issues as I am with my own code base. I decided to test with a clone of this repo as 'bss' and replacing .env files with my info and am experiencing the same issues. I'm on MacOS.

Steps to reproduce & Troubleshooting

  1. 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.
  2. Execute brownie run scripts/deploy.py --network ganache-local
 ~/Documents/Projects/Web3/bss (main●●)$ brownie run scripts/deploy.py --network ganache-local 
Brownie v1.17.1 - Python development framework for Ethereum

BssProject 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. Add gas_limit param to fund_me.withdraw({"from": account}) -> fund_me.withdraw({"from": account, 'gas_limit': 6721975})
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. I've also tried deleting build artifacts & redeploying ganache ui.

Environment

Brownie v.1.17.1
Ganache CLI v6.12.2 (ganache-core: 2.13.2)
Node v16.8.0
Npm v7.21.0
Truffle v5.0.22

The only part of the code that has been changed from the repo is adding the gas_limit. Still happy to share the code if request. For the life of me, I can't figure what invalid opcode is causing this to revert . . . Any help would be greatly appreciated!

Thanks in advance!
@GratefulDave

@PatrickAlphaC
Copy link
Owner

Thanks for the kind words!

This is likely due to the function you're calling... it doesn't like what you're doing. What happens when you use just the regular development network? Like brownie run scripts/deploy.py?

Or... did you install with pipx or pip?

@Madgeniusblink
Copy link

I am getting the same error after adding

`def withdraw():
fund_me = FundMe[-1]
account = get_account()
fund_me.withdraw({"from": account})

def main():
fund()
withdraw()`

ERROR
`Brownie v1.17.1 - Python development framework for Ethereum

BrownieFundMeProject is the active project.

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

File "brownie/_cli/run.py", line 54, in main
_include_frame=True,
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 1509, in transact
allow_revert=tx["allow_revert"],
File "brownie/network/account.py", line 657, in transfer
silent,
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.`

@GratefulDave
Copy link
Author

GratefulDave commented Dec 3, 2021

@PatrickAlphaC I installed with pipx. This was initially in the discussion here if you want to see all of the things we have tried. One user got it working. A few others have this same issue

@PatrickAlphaC
Copy link
Owner

There might be something wrong with your local network... what happens when you remove the network flag?

@GratefulDave
Copy link
Author

If I import deploy_fund_me() and run it prior to running fund() & withdraw() to ganache-cli it works properly. If I don't do that it can't find an instance of FundMe[-1]. I believe that happens because ganache-cli isn't persistent.

@PatrickAlphaC
Copy link
Owner

Right, that makes sense. I'm thinking it's something wrong with your local chain... what happens when you try it on a testnet?

@GratefulDave
Copy link
Author

GratefulDave commented Dec 6, 2021

If I run deploy.py and then fund_and_withdraw.py (w/o redeploying the mocks) I get the same error:

Brownie v1.17.1 - Python development framework for Ethereum

BrownieFundMeProject is the active project.

Running 'scripts/fund_and_withdraw.py::main'...
11912418682380178
The current entry fee is 11912418682380178
Funding
  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 27, in main
    fund()
  File "./scripts/fund_and_withdraw.py", line 13, in fund
    tx = fund_me.fund({"from": account, "value": entrance_fee})
  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: You need to spend more ETH!'. This transaction will likely revert. If you wish to broadcast, you must set the gas limit manually.

I also have ~17.5 ETH in my Rinkeby test account.

@PatrickAlphaC
Copy link
Owner

ValueError: Gas estimation failed: 'execution reverted: You need to spend more ETH!'

This means you're not sending enough ETH, and your entrance fee is off. How are you getting the entrance fee?

@GratefulDave
Copy link
Author

I cloned your repo and added my .env file. Same code.

@PatrickAlphaC
Copy link
Owner

Do you have ETH in your metamask?

@GratefulDave
Copy link
Author

I have Rinkeby eth as well. I was able to get this to work on ganache-local when I reinstalled on old machine. This appears to be a conflict with my installation/environment. @cromewar suggested I uninstall my versions of Python and try to reinstall them.

I was excited getting a new MacBook Pro M1 Max Pro next week, but I've heard that there are some issues with web3 and the new silicon. :/

I do appreciate your help @PatrickAlphaC. If you can suggest how I might be able to diagnose - that would be great. If not, please feel free to close this ticket.

@PatrickAlphaC
Copy link
Owner

Closing for now, if it's an issue with the M1... I won't be much help here sorry :/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants