From 806e66dfd64cfda3fc124fef0d8803c5a37ede40 Mon Sep 17 00:00:00 2001 From: daveroga Date: Tue, 21 Jan 2025 15:50:23 +0100 Subject: [PATCH] add script to compute create2 address for contracts --- hardhat.config.ts | 16 +++++++++++++- scripts/maintenance/computeCreate2Address.ts | 22 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 scripts/maintenance/computeCreate2Address.ts diff --git a/hardhat.config.ts b/hardhat.config.ts index 94e2ce18..28646e36 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -140,7 +140,21 @@ const config: HardhatUserConfig = { ignition: { strategyConfig: { create2: { - salt: "0x000000000000000000000000000000000000000000f4179bc3e4988a1a06f8d1", // 20 bytes: zero address; 1 byte: 00 - no cross chain protection, 11 bytes - random salt. + salt: "0x000000000000000000000000000000000000000000f4179bc3e4988a1a06f8d1", + // 20 bytes: zero address; 1 byte: 00 - no cross chain protection, 11 bytes - random salt. + // + // CreateX implements different safeguarding mechanisms depending on the encoded values in the salt + // * (`||` stands for byte-wise concatenation): + // => salt (32 bytes) = 0xbebebebebebebebebebebebebebebebebebebebe||ff||1212121212121212121212 + // * - The first 20 bytes (i.e. `bebebebebebebebebebebebebebebebebebebebe`) may be used to + // * implement a permissioned deploy protection by setting them equal to `msg.sender`, + // -> In our case we set it to zero address to disable this protection + // * - The 21st byte (i.e. `ff`) may be used to implement a cross-chain redeploy protection by + // * setting it equal to `0x01`, + // -> In our case we set it to `0x00` to disable this protection + // * - The last random 11 bytes (i.e. `1212121212121212121212`) allow for 2**88 bits of entropy + // * for mining a salt. + // -> In our case f4179bc3e4988a1a06f8d1 }, }, requiredConfirmations: 5, diff --git a/scripts/maintenance/computeCreate2Address.ts b/scripts/maintenance/computeCreate2Address.ts new file mode 100644 index 00000000..46b2bbbc --- /dev/null +++ b/scripts/maintenance/computeCreate2Address.ts @@ -0,0 +1,22 @@ +import { ethers } from "hardhat"; + +async function main() { + const byteCode = ""; + const salt = "0x000000000000000000000000000000000000000000f4179bc3e4988a1a06f8d1"; // Replace your salt here; + const create2Deployer = "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed"; // This is deployer address for CreateX in every network + + const create2ContractAddress = ethers.getCreate2Address( + create2Deployer, + ethers.keccak256(salt), + ethers.keccak256(byteCode), + ); + + console.log("Create2 computed address:", create2ContractAddress); +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + });