wighawag / hardhat-deploy

hardhat deployment plugin
MIT License
1.19k stars 292 forks source link

Unable to deploy using create2 on private chain. #337

Open hickscorp opened 2 years ago

hickscorp commented 2 years ago

When trying to deploy our diamond contracts on our private chain, we get the following error:

$ /path/node_modules/.bin/hardhat --network staging deploy
Nothing to compile
No need to generate any newer typings.
sending eth to create2 contract deployer address (0x3fab184622dc19b6109349b94811493bf2a45362) (tx: 0xa1b6b912160ec5fba1095876574bf712210e48e1f2338de3bc689a059044f735)...
deploying create2 deployer contract (at 0x4e59b44847b379578588920ca78fbf26c0b4956c) using deterministic deployment (https://github.com/Arachnid/deterministic-deployment-proxy)An unexpected error occurred:

Error: ERROR processing /path/deploy/10_deploySpc.ts:
Error: legacy pre-eip-155 transactions not supported (error={"name":"ProviderError","code":-32000,"_isProviderError":true}, method="sendTransaction", transaction="0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222", code=UNSUPPORTED_OPERATION, version=providers/5.6.8)
    at Logger.makeError (/path/node_modules/@ethersproject/logger/src.ts/index.ts:261:28)
    at Logger.throwError (/path/node_modules/@ethersproject/logger/src.ts/index.ts:273:20)
    at checkError (/path/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:119:16)
    at Web3Provider.<anonymous> (/path/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:603:20)
    at step (/path/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:48:23)
    at Object.throw (/path/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:29:53)
    at rejected (/path/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:21:65)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at DeploymentsManager.executeDeployScripts (/path/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1222:19)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async DeploymentsManager.runDeploy (/path/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
    at async SimpleTaskDefinition.action (/path/node_modules/hardhat-deploy/src/index.ts:438:5)
    at async Environment._runTaskDefinition (/path/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at async Environment.run (/path/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at async SimpleTaskDefinition.action (/path/node_modules/hardhat-deploy/src/index.ts:584:32)
    at async Environment._runTaskDefinition (/path/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at async Environment.run (/path/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at async SimpleTaskDefinition.action (/path/node_modules/hardhat-deploy/src/index.ts:669:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Do we need to create the deployment proxy ourselves? If so, maybe a bit of documentation would be useful. If we deploy it ourselves, how would we tell hardhat-deploy at which address the deployment proxy is? Would a deployment of https://github.com/Arachnid/deterministic-deployment-proxy be sufficient?

hickscorp commented 2 years ago

So - it seems that the function trying to get the deployment proxy up and running is using this:

  public async getDeterministicDeploymentFactoryDeploymentTx(): Promise<string> {
    const info = await this.getDeterminisityDeploymentInfo();
    return (
      info?.signedTx ||
      '0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222'
    );
  }

On the hardhat network it seems because the fake hardhat network hasn't passed the EIP155 block. On an existing chain, it's very likely that these contracts were deployed pre-EIP155 - so the transaction was accepted. On a private chain though, it's a different story - EIP155 has "already happened" and this transaction isn't accepted (It might be missing the chain ID, as EIP155 is a counter-measure to cross-chain transaction replay attacks I think?)...

What do you advise? It seems that it there would be a way to customize this - as the function checks info?.signedTx etc before slapping the obsolete transaction as a default. But we have no idea how to generate this transaction.

Could someone please help?

hickscorp commented 2 years ago

Also - as we could start testing our contracts on our staging chain without having to deploy them deterministically, I've tried to deploy them without deterministic options. Well - it seems that hardhat-deploy is still trying to deploy the contract factory for create2 even when not asked to use deterministic stuff. Is there a way to deploy diamonds without any deterministic routines involved?

hickscorp commented 2 years ago

Since I cannot seem to deploy diamonds without deterministic deploys, I tried to dig deeper into how we could have our own deployment factory. I ended up generating our own. In hardhat.config.ts it looks like something like this:

  ...,
  deterministicDeployment: {
    // Hardhat / Localhost.
    31337: {
      deployer: '0x8f706cE664d63559dcf239b9A4A8C29aBef1BCf7',
      signedTx: '0xf8a78085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf382f4f5a01ea073da86af6d8a8215f0fe8986181c291d61dcaab557895f12d22c16764d77a04fd5bc7be48eac759e8afbbe6c7de973ae4d12755638a0a3c5a48bd22cfd1e0b',
      factory: '0x31683ed9d43A48D373c20Db3CC1965Ecc59e3E48',
      funding: '10000000000000000'
    },
    // Staging.
    18021981: {
      deployer: '0xbEd845ccFe1a30B3a432132Fd90A6f79F2f05513',
      signedTx: '0xf8a98085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3840225fcdea0b09945dab4f6cd5f05fdf73c5df5ceefc8b7225058d588c50a8138525a189791a03581e80fe3b3341cb4cb6aa1f9224f91c00ef8fefeef8860d9775e02d63491b1',
      factory: '0x03813865D8c17c5f2C05496701F471b87B0cBf38',
      funding: '10000000000000000'
    },
    // Production.
    18021982: {
      deployer: '0x17AdB725223aEa5F990Fcdf1Cd02E3284F2ecc90',
      signedTx: '0xf8a98085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3840225fce0a0fe675277a1e0d7f06b32bdd45a7838b34842b5015151d26c510af0bf5c07e80ca00d2214d48dad3e2628b640d9eee2d0d7d7fc8b3721d2c31b1f994fcff7c37f74',
      factory: '0x882eB7eD0758c5Db6DEd44a04655dFa252cfA521',
      funding: '10000000000000000'
    }
  },
  ...

Against all odds, this works great locally. It seems that create2 is delegated properly to the factory using the signed transactions. However when trying to deploy in one of our live chains, I get the following errors:

Error: ERROR processing /project/deploy/10_deploySpc.ts:
Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="execution reverted", method="estimateGas", transaction={"from":"0x717634cfe06FFAB2CEAA7fcf1b9019813f4B25FE","to":"0x03813865D8c17c5f2C05496701F471b87B0cBf38","data":"0x...TRUNCATED, TOO LONG!!!","accessList":null}, error={"name":"ProviderError","code":-32000,"_isProviderError":true}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.6.8)
    at Logger.makeError (/project/node_modules/@ethersproject/logger/src.ts/index.ts:261:28)
    at Logger.throwError (/project/node_modules/@ethersproject/logger/src.ts/index.ts:273:20)
    at checkError (/project/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:78:20)
    at Web3Provider.<anonymous> (/project/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:603:20)
    at step (/project/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:48:23)
    at Object.throw (/project/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:29:53)
    at rejected (/project/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:21:65)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at DeploymentsManager.executeDeployScripts (/project/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1222:19)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async DeploymentsManager.runDeploy (/project/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
    at async SimpleTaskDefinition.action (/project/node_modules/hardhat-deploy/src/index.ts:438:5)
    at async Environment._runTaskDefinition (/project/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at async Environment.run (/project/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at async SimpleTaskDefinition.action (/project/node_modules/hardhat-deploy/src/index.ts:584:32)
    at async Environment._runTaskDefinition (/project/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at async Environment.run (/project/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at async SimpleTaskDefinition.action (/project/node_modules/hardhat-deploy/src/index.ts:669:5)
error Command failed with exit code 1.

It seems to me that hardhat is trying to send a transaction to 0x03813865D8c17c5f2C05496701F471b87B0cBf38 which is supposed to be the singleton deployment factory, without having it deployed first... I don't see hardhat trying to provision 0x03813865D8c17c5f2C05496701F471b87B0cBf38 with eth, nor to deploy the singleton deployer contract. So I also tried to set live: false to our staging network, thinking that it could indicate hardhat to deploy the singleton deployer contract - same error. Any idea what could be happening? Is hardhat deploying the factory itself, or do I need to do anything?

hickscorp commented 2 years ago

A bit more information... I was able to get a tad further:

$ /project/node_modules/.bin/hardhat --network production deploy
Nothing to compile
No need to generate any newer typings.
sending eth to create2 contract deployer address (0xbEd845ccFe1a30B3a432132Fd90A6f79F2f05513) (tx: 0xd9eda6d0f72d59decae22841626699c012482c79694ee2b2f92867b2aa4f63c5)...
deploying create2 deployer contract (at 0x03813865D8c17c5f2C05496701F471b87B0cBf38) using deterministic deployment (https://github.com/Arachnid/deterministic-deployment-proxy) (tx: 0x1ad3e523d54d7415274ad55929d0f63cfd3f9263c08277bfe6a10d94556d7667)...
deploying "SpcTopFacet"closed {"name":"SocketError","code":"UND_ERR_SOCKET","socket":{"bytesWritten":36625,"bytesRead":26422},"transactionHash":"0x08df44fb3a1817587e24bf30ad1f2ab79a50d79b6f29aaaee43debb52154b5d3"} SocketError: closed
    at TLSSocket.onSocketClose (/project/node_modules/undici/lib/client.js:967:31)
    at TLSSocket.emit (events.js:412:35)
    at TLSSocket.emit (domain.js:475:12)
    at net.js:686:12
    at TCP.done (_tls_wrap.js:564:7) {
  code: 'UND_ERR_SOCKET',
  socket: {
    localAddress: undefined,
    localPort: undefined,
    remoteAddress: undefined,
    remotePort: undefined,
    remoteFamily: undefined,
    timeout: undefined,
    bytesWritten: 36625,
    bytesRead: 26422
  },
  transactionHash: '0x08df44fb3a1817587e24bf30ad1f2ab79a50d79b6f29aaaee43debb52154b5d3'
}
An unexpected error occurred:

Error: ERROR processing /project/deploy/10_deploySpc.ts:
SocketError: closed
    at TLSSocket.onSocketClose (/project/node_modules/undici/lib/client.js:967:31)
    at TLSSocket.emit (events.js:412:35)
    at TLSSocket.emit (domain.js:475:12)
    at net.js:686:12
    at TCP.done (_tls_wrap.js:564:7)
    at DeploymentsManager.executeDeployScripts (/project/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1222:19)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async DeploymentsManager.runDeploy (/project/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
    at async SimpleTaskDefinition.action (/project/node_modules/hardhat-deploy/src/index.ts:438:5)
    at async Environment._runTaskDefinition (/project/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at async Environment.run (/project/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at async SimpleTaskDefinition.action (/project/node_modules/hardhat-deploy/src/index.ts:584:32)
    at async Environment._runTaskDefinition (/project/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at async Environment.run (/project/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at async SimpleTaskDefinition.action (/project/node_modules/hardhat-deploy/src/index.ts:669:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Now the weirdest thing is happening - hardhat console --network staging works-ish: I can query ether balance, and some other things from existing contracts - but some methods just return data that has nothing to do with the state of the chain - querying the same node with another project that uses truffle just works fine. Our dapp also works fine through Metamask...

And trying to deploy again, or simply running `hre.deployments.run() from the working console gives me:

Error: ERROR processing /project/deploy/10_deploySpc.ts:
SocketError: closed
    at TLSSocket.onSocketClose (/project/node_modules/undici/lib/client.js:967:31)
    at TLSSocket.emit (events.js:412:35)
    at TLSSocket.emit (domain.js:475:12)
    at net.js:686:12
    at TCP.done (_tls_wrap.js:564:7)
    at DeploymentsManager.executeDeployScripts (/project/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1222:19)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async DeploymentsManager.runDeploy (/project/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
    at async SimpleTaskDefinition.action (/project/node_modules/hardhat-deploy/src/index.ts:438:5)
    at async Environment._runTaskDefinition (/project/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at async Environment.run (/project/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at async SimpleTaskDefinition.action (/project/node_modules/hardhat-deploy/src/index.ts:584:32)
    at async Environment._runTaskDefinition (/project/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at async Environment.run (/project/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at async SimpleTaskDefinition.action (/project/node_modules/hardhat-deploy/src/index.ts:669:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Is there some kind of hidden state file that hardhat uses somewhere? I always delete artifacts, cache and deployments... But is there something else?

jamesduncombe commented 2 years ago

Related to https://github.com/rsksmart/rskj/issues/1805, dropping to v2.9.7 of HH seemed to fix it.

hickscorp commented 2 years ago

Yep - thanks @jamesduncombe !!!

hickscorp commented 2 years ago

@wighawag any idea why we had to downgrade?

wighawag commented 2 years ago

@hickscorp hardhat might have introduced a breaking change, did not get a chance to look deeper