From f606790a42ef2133bb6885e0e24fcf41b51a66f3 Mon Sep 17 00:00:00 2001 From: Kelvin Fichter Date: Tue, 19 Jul 2022 15:33:49 +0200 Subject: [PATCH] fix(ctb): bug in L2 genesis script Fixes a bug in the Bedrock L2 genesis script where storage slots were being set in the implementation rather than the proxy, which (obviously) broke various things that the SDK relies on. --- .changeset/clever-news-smile.md | 5 +++ .../contracts-bedrock/tasks/genesis-l2.ts | 32 +++++++++++++------ 2 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 .changeset/clever-news-smile.md diff --git a/.changeset/clever-news-smile.md b/.changeset/clever-news-smile.md new file mode 100644 index 0000000000000..3b87429e89903 --- /dev/null +++ b/.changeset/clever-news-smile.md @@ -0,0 +1,5 @@ +--- +'@eth-optimism/contracts-bedrock': patch +--- + +Fixes a bug in the L2 Bedrock genesis script diff --git a/packages/contracts-bedrock/tasks/genesis-l2.ts b/packages/contracts-bedrock/tasks/genesis-l2.ts index 1f911f194c622..8b5b2bd66afa5 100644 --- a/packages/contracts-bedrock/tasks/genesis-l2.ts +++ b/packages/contracts-bedrock/tasks/genesis-l2.ts @@ -170,6 +170,28 @@ task('genesis-l2', 'create a genesis config') } if (predeployAddrs.has(ethers.utils.getAddress(addr))) { + const predeploy = Object.entries(predeploys).find(([, address]) => { + return ethers.utils.getAddress(address) === addr + }) + + // Really shouldn't happen, since predeployAddrs is a set generated from predeploys. + if (predeploy === undefined) { + throw new Error('could not find address') + } + + const name = predeploy[0] + if (variables[name]) { + const storageLayout = await getStorageLayout(hre, name) + if (storageLayout === undefined) { + throw new Error(`cannot find storage layout for ${name}`) + } + const slots = computeStorageSlots(storageLayout, variables[name]) + + for (const slot of slots) { + alloc[addr].storage[slot.key] = slot.val + } + } + alloc[addr].storage[implementationSlot] = toCodeAddr(addr) } } @@ -247,16 +269,6 @@ task('genesis-l2', 'create a genesis config') code: artifact.deployedBytecode, storage: {}, } - - const storageLayout = await getStorageLayout(hre, name) - if (storageLayout === undefined) { - throw new Error(`cannot find storage layout for ${name}`) - } - const slots = computeStorageSlots(storageLayout, variables[name]) - - for (const slot of slots) { - alloc[allocAddr].storage[slot.key] = slot.val - } } const portal = await hre.deployments.get('OptimismPortalProxy')