Cannot deploy NickFactory: invalid opcode error
Version of Hardhat
2.20.0
What happened?
We are migrating the @lukso.lsp-smart-contracts codebase to the latest version of Hardhat and to ethers v6.
I have a test script running to try to deploy the NickFactory contract for CREATE2 deployment, available on this repository:
https://github.com/Arachnid/deterministic-deployment-proxy
Running the Deployment Transaction fails with the following error below:
0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222
Minimal reproduction steps
Here is my code snippet:
// from: https://github.com/Arachnid/deterministic-deployment-proxy
static readonly contractAddress = '0x4e59b44847b379578588920ca78fbf26c0b4956c';
static readonly factoryTx =
'0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222';
static readonly factoryDeployer = '0x3fab184622dc19b6109349b94811493bf2a45362';
static readonly deploymentGasPrice = 100e9;
static readonly deploymentGasLimit = 100000;
static readonly factoryDeploymentFee = (
Create2Factory.deploymentGasPrice * Create2Factory.deploymentGasLimit
).toString();
const currentSigner = (await signer) ?? (await this.signer);
const tx = await currentSigner.sendTransaction({
to: Create2Factory.factoryDeployer,
value: BigInt(Create2Factory.factoryDeploymentFee),
});
await tx.wait();
// TODO: this transaction keeps failing with the following error, although the deployment transaction
// for the Create2Factory has not changed:
// `Error: VM Exception while processing transaction: invalid opcode`
await this.provider.send('eth_sendTransaction', [
{
data: Create2Factory.factoryTx,
},
]);
if (!(await this._isFactoryDeployed())) {
throw new Error('fatal: failed to deploy deterministic deployer');
}
Search terms
NickFactory, create2, invalid opcode, error
hey @CJ42, did this code work in ethers v5? is your contract payable? what happens if you just don’t send along value: BigInt(Create2Factory.factoryDeploymentFee), in the currentSigner.sendTransaction?
Closing due to lack of response. However, I am happy to reopen this if more information can be provided.
yes had the same issue. if you want to repoduce, you can use the Create2 factory and try to deploy the factory using deployFactory
Its working on their hardhat version, used to work on mind as well but got broken after updating my hardhat/ethers versions
Is this running on a Hardhat node or a live network? We are happy to look into it, but given the complexity of your setup and our limited time, we need more details to effectively address this. Could you please provide a minimal reproducible example? A sample Hardhat project with the minimal dependencies needed to reproduce the issue would be really helpful.
its not working running on the hardhat node but used to work. Not entirely sure it's ethers v6 issue or hardhat. It should work on any EVM network. One way you could test it is to try it in a hardhat enviromnet and run this script
import { ethers } from "hardhat";
import { serialize } from "@ethersproject/transactions";
async function main() {
const [deployer] = await ethers.getSigners();
const provider = ethers.provider;
console.log("Deploying factory...");
const factoryDeployer = "0x3fab184622dc19b6109349b94811493bf2a45362";
const factoryDeploymentFee = "10000000000000000"; // 0.01 ETH
const factoryTx =
"0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222";
const factoryAddress = "0x4e59b44847b379578588920ca78fbf26c0b4956c";
// Check if the factory is already deployed
const code = await provider.getCode(factoryAddress);
if (code.length > 2) {
console.log("Factory is already deployed.");
return;
}
// Deploy the factory
const tx = await deployer.sendTransaction({
data: serialize({
to: factoryDeployer,
value: BigInt(factoryDeploymentFee),
}),
});
await tx.wait();
const serialized = serialize({ data: factoryTx });
const deployTx = await deployer.sendTransaction({ data: serialized });
await deployTx.wait();
// Verify factory deployment
const deployedCode = await provider.getCode(factoryAddress);
if (deployedCode.length <= 2) {
throw new Error("Fatal: Failed to deploy factory");
}
console.log("Factory deployed successfully!");
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
Hey @skimaharvey, sorry but I don't think that's enough.
The alleged issue here is that Hardhat stopped working when the CREATE2 opcode is used. This is highly unlikely, so we need good reproduction steps that prove that this is the case. Specifically:
- A minimal reproduction that uses CREATE2 and works in
[email protected] - Another minimal reproduction that uses CREATE2 and doesn't work in
hardhat@latest
The reason I say this is highly unlikely is that Hardhat is tested with real mainnet blocks, that frequently use the CREATE2 opcode. If this weren't working, we would've already caught it.
Tentatively closing, happy to re-open if someone can demonstrate that there's a bug.
I dont think create2 is the issue. its deploying the nick factory that fails. I really dont see how we could mess it up. we are just re-using the nick factory script
I tried with different hardfork and its not working...
I will try to set up a repo that proove it