question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

REVERT opcode in factory pattern when using a forked chain

See original GitHub issue

When working with a forked chain, transactions that create a contract and call a function of the newly created contract are REVERTED.

Expected Behavior

Such transactions execute successfully on a non-forked ganache-cli instance or on the target chain (goerli or mainnet). They should behave the same on a forked ganache chain.

Current Behavior

Transaction REVERT’s with

Error: Returned error: VM Exception while processing transaction: revert
    at XMLHttpRequest._onHttpResponseEnd (/Users/Elena/colonyNetwork/node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request.js:318:1)
    at XMLHttpRequest._setReadyState (/Users/Elena/colonyNetwork/node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request.js:208:1)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/Elena/colonyNetwork/node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)
    at XMLHttpRequest.request.onreadystatechange (/Users/Elena/colonyNetwork/node_modules/truffle/build/webpack:/~/web3/~/web3-providers-http/src/index.js:96:1)
    at /Users/Elena/colonyNetwork/node_modules/truffle/build/webpack:/packages/truffle-provider/wrapper.js:112:1
    at /Users/Elena/colonyNetwork/node_modules/truffle/build/webpack:/~/web3-eth/~/web3-core-requestmanager/src/index.js:140:1
    at Object.ErrorResponse (/Users/Elena/colonyNetwork/node_modules/truffle/build/webpack:/~/web3-eth/~/web3-core-helpers/src/errors.js:29:1)

Transaction details output from running ganache-cli fork in verbose mode:

eth_sendTransaction
   > {
   >   "jsonrpc": "2.0",
   >   "id": 9,
   >   "method": "eth_sendTransaction",
   >   "params": [
   >     {
   >       "from": "0x7afb67a48c6a3e5c15a36454a6e7602dbcdd3b5f",
   >       "gas": "0x6691b7",
   >       "to": "0x79073fc2117dd054fcedacad1e7018c9cbe3ec0b",
   >       "data": "0x08eb0d2c000000000000000000000000d468b86abb0c58f0b948b36a8769829abd66d8af",
   >       "gasPrice": "0x4a817c800"
   >     }
   >   ]
   > }
 <   {
 <     "id": 9,
 <     "jsonrpc": "2.0",
 <     "result": "0x4c7878844a77133d9fbaebfeabb59f7e2b952f0531dc3344ac51b78556536d3b",
 <     "error": {
 <       "message": "VM Exception while processing transaction: revert",
 <       "code": -32000,
 <       "data": {
 <         "0x4c7878844a77133d9fbaebfeabb59f7e2b952f0531dc3344ac51b78556536d3b": {
 <           "error": "revert",
 <           "program_counter": 297,
 <           "return": "0x"
 <         },
 <         "stack": "o: VM Exception while processing transaction: revert\n    at Function.o.fromResults (/Users/Elena/colonyNetwork/node_modules/ganache-cli/build/ganache-core.node.cli.js:10:81931)\n    at /Users/Elena/colonyNetwork/node_modules/ganache-cli/build/ganache-core.node.cli.js:47:115772\n    at /Users/Elena/colonyNetwork/node_modules/ganache-cli/build/ganache-core.node.cli.js:47:96183\n    at p (/Users/Elena/colonyNetwork/node_modules/ganache-cli/build/ganache-core.node.cli.js:47:95840)\n    at /Users/Elena/colonyNetwork/node_modules/ganache-cli/build/ganache-core.node.cli.js:47:95893\n    at t.default (/Users/Elena/colonyNetwork/node_modules/ganache-cli/build/ganache-core.node.cli.js:52:475253)\n    at /Users/Elena/colonyNetwork/node_modules/ganache-cli/build/ganache-core.node.cli.js:47:96807\n    at w.n.emit (/Users/Elena/colonyNetwork/node_modules/ganache-cli/build/ganache-core.node.cli.js:61:1211582)\n    at /Users/Elena/colonyNetwork/node_modules/ganache-cli/build/ganache-core.node.cli.js:61:1850380\n    at /Users/Elena/colonyNetwork/node_modules/ganache-cli/build/ganache-core.node.cli.js:61:1850403\n    at /Users/Elena/colonyNetwork/node_modules/ganache-cli/build/ganache-core.node.cli.js:61:500010\n    at /Users/Elena/colonyNetwork/node_modules/ganache-cli/build/ganache-core.node.cli.js:2:26262\n    at i (/Users/Elena/colonyNetwork/node_modules/ganache-cli/build/ganache-core.node.cli.js:2:41317)\n    at /Users/Elena/colonyNetwork/node_modules/ganache-cli/build/ganache-core.node.cli.js:2:21785\n    at process._tickCallback (internal/process/next_tick.js:61:11)",
 <         "name": "o"
 <       }
 <     }
 <   }

Possible Solution

Although this issue bears resemblance to https://github.com/trufflesuite/ganache-cli/issues/646 , testing the failing transactions with passing the max gas (using { gas: '0x6691b7' }) doesn’t produce different results.

We have also tested whether this is a regression bug introduced in the recent --fork logic fixes. However the issue persists with all of the following ganache-cli versions going back to January this year: 6.4.4-beta.0 6.4.3 6.4.3-beta.0 6.4.2 6.4.0 6.3.0

Steps to Reproduce (for bugs)

To reproduce against a goerli fork run the following in a truffle console after forking the chain:

const colonyNetwork = await IColonyNetwork.at("0x79073fc2117dD054FCEdaCad1E7018C9CbE3ec0B")

await colonyNetwork.createColony("0xD468b86aBB0C58F0B948b36a8769829aBD66d8AF")
Error: Returned error: VM Exception while processing transaction: revert
    at XMLHttpRequest._onHttpResponseEnd 

The createColony call is one of the few factory methods we use to instantiate a new Colony in the network. The others are initialiseReputationMining and startNetCycle methods on IColonyNetwork which exhibit the same behaviour. You’ll need the IColonyNetwork build artefact from https://github.com/JoinColony/colonyNetwork/tree/develop/contracts

Context

We are currently blocked and unable to test key areas of functionality in the Colony Network on testnet and mainnet. Also it blocks any regression testing we can do on new functionality and fixes. Basically it blocks our go-live.

Your Environment

  • Version used: 6.4.3
  • Version of Truffle/Remix/Other tools used: Truffle v5.0.18 (core: 5.0.18) Solidity - 0.5.8 (solc-js) Node v10.12.0 Web3.js v1.0.0-beta.37
  • Operating System and version (include distro if Linux): OSX
  • Link to your project or repro gist: https://github.com/JoinColony/colonyNetwork
  • Commit hash to use with above link for reproduction: latest

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
areacommented, Oct 21, 2019

I’m testing with the current beta, and it looks like this is fixed - many thanks! Looking forward to the mainline release!

1reaction
niklasbcommented, Jul 17, 2019

I have personally also run into your second issue. I filed an issue for this at https://github.com/trufflesuite/ganache-core/issues/454 @davidmurdoch which includes a minimal reproducer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Contract factories and clones - Solidity developer
How to deploy contracts within contracts as easily and gas-efficient as possible. The factory design pattern is a pretty common pattern used in...
Read more >
Getting the most out of CREATE2 - OpenZeppelin blog
Enter CREATE2. CREATE2 is a new opcode introduced in the Constantinople hard fork to provide an alternative to the original CREATE. The main ......
Read more >
EIP-1153: Transient storage opcodes
This EIP requires a hard fork to implement. Since this EIP does not change behavior of any existing opcodes, it is backwards compatible...
Read more >
A Sneaky Solidity Implementation of a Sealed-Bid Auction
SneakyAuction” combines the CREATE2 opcode and state proofs to guarantee bid privacy without requiring bidders to lock up more collateral ...
Read more >
EIP-3074: AUTH and AUTHCALL opcodes
In the case of a fork (chain ID change), the invoker can be redeployed. This can be automated with a factory. By not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found