Commit 118e9be0 authored by Mark Tyneway's avatar Mark Tyneway

contracts-bedrock: add some comments + cleanup

parent 1475b286
...@@ -22,6 +22,7 @@ task('check-l2-config', 'Validate L2 config') ...@@ -22,6 +22,7 @@ task('check-l2-config', 'Validate L2 config')
) )
const bridge = await OptimismMintableERC20Factory.bridge() const bridge = await OptimismMintableERC20Factory.bridge()
console.log(`OptimismMintableERC20Factory.bridge() -> ${bridge}`)
if (bridge !== predeploys.L2StandardBridge) { if (bridge !== predeploys.L2StandardBridge) {
throw new Error( throw new Error(
`L2StandardBridge not set correctly. Got ${bridge}, expected ${predeploys.L2StandardBridge}` `L2StandardBridge not set correctly. Got ${bridge}, expected ${predeploys.L2StandardBridge}`
......
...@@ -58,6 +58,7 @@ const getStorageLayout = async ( ...@@ -58,6 +58,7 @@ const getStorageLayout = async (
throw new Error(`Cannot locate storageLayout for ${name}`) throw new Error(`Cannot locate storageLayout for ${name}`)
} }
// Find the contract and source from the build info
const findContractAndSource = (name: string, buildInfo: BuildInfo) => { const findContractAndSource = (name: string, buildInfo: BuildInfo) => {
const sources = buildInfo.output.sources const sources = buildInfo.output.sources
const contracts = buildInfo.output.contracts const contracts = buildInfo.output.contracts
...@@ -107,18 +108,21 @@ const replaceImmutables = async ( ...@@ -107,18 +108,21 @@ const replaceImmutables = async (
outputContract.evm.deployedBytecode.immutableReferences outputContract.evm.deployedBytecode.immutableReferences
const names = {} const names = {}
// Recursively fine all of the immutables by traversing the solc output ast
const findNames = (ast: any) => { const findNames = (ast: any) => {
// console.log(ast) // Add the name of the variable if it is an immutable
const isImmutable = ast.mutability === 'immutable' const isImmutable = ast.mutability === 'immutable'
const isASTNode = typeof ast.name === 'string' && typeof ast.id === 'number' const isASTNode = typeof ast.name === 'string' && typeof ast.id === 'number'
if (isASTNode && isImmutable) { if (isASTNode && isImmutable) {
names[ast.name] = ast.id names[ast.name] = ast.id
} }
// Iterate over each node
if (Array.isArray(ast.nodes)) { if (Array.isArray(ast.nodes)) {
for (const node of ast.nodes) { for (const node of ast.nodes) {
findNames(node) findNames(node)
} }
} }
// Handle contracts that are inherited from
if (Array.isArray(ast.baseContracts)) { if (Array.isArray(ast.baseContracts)) {
for (const baseContract of ast.baseContracts) { for (const baseContract of ast.baseContracts) {
if (baseContract.baseName) { if (baseContract.baseName) {
...@@ -137,6 +141,7 @@ const replaceImmutables = async ( ...@@ -137,6 +141,7 @@ const replaceImmutables = async (
let deployedBytecode = artifact.deployedBytecode let deployedBytecode = artifact.deployedBytecode
const presize = deployedBytecode.length const presize = deployedBytecode.length
// For each of the immutables, put the value into the bytecode
for (const [key, value] of Object.entries(immutables)) { for (const [key, value] of Object.entries(immutables)) {
const astId = names[key] const astId = names[key]
if (!astId) { if (!astId) {
...@@ -157,6 +162,7 @@ const replaceImmutables = async ( ...@@ -157,6 +162,7 @@ const replaceImmutables = async (
} }
} }
// Ensure that the bytecode is the same size
if (presize !== deployedBytecode.length) { if (presize !== deployedBytecode.length) {
throw new Error( throw new Error(
`Size mismatch! Before ${presize}, after ${deployedBytecode.length}` `Size mismatch! Before ${presize}, after ${deployedBytecode.length}`
...@@ -369,6 +375,8 @@ task('genesis-l2', 'create a genesis config') ...@@ -369,6 +375,8 @@ task('genesis-l2', 'create a genesis config')
} }
} }
// Note: this currently only supports up to 32 byte values.
// Things less than 32 bytes will be left padded with 0 bytes
const immutables = { const immutables = {
OptimismMintableERC20Factory: { OptimismMintableERC20Factory: {
bridge: predeploys.L2StandardBridge, bridge: predeploys.L2StandardBridge,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment