Skip to content

Commit 700dcbb

Browse files
authored
contracts-bedrock: genesis builder (#2781)
* contracts-bedrock: hardhat genesis-l1 * contracts-bedrock: hardhat genesis-l2 * core-utils: update types * contracts-bedrock: hardhat rollup-config * contracts-bedrock: update deploy scripts * contracts-governance: more solc output * contracts-bedrock: deploy config * contracts-bedrock: general fixes * ops-bedrock: use new script * lint * lint: fix
1 parent a828da9 commit 700dcbb

25 files changed

Lines changed: 823 additions & 1764 deletions

.changeset/fair-poets-exist.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@eth-optimism/contracts-bedrock': patch
3+
---
4+
5+
Add genesis script

.changeset/lemon-files-wait.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@eth-optimism/core-utils': minor
3+
---
4+
5+
Update geth's Genesis type to work with modern geth

ops-bedrock/devnet-up.sh

Lines changed: 43 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ L1_URL="http://localhost:8545"
3333
L2_URL="http://localhost:9545"
3434

3535
CONTRACTS_BEDROCK=./packages/contracts-bedrock
36+
NETWORK=devnetL1
3637

3738
# Helper method that waits for a given URL to be up. Can't use
3839
# cURL's built-in retry logic because connection reset errors
@@ -46,23 +47,32 @@ function wait_up {
4647
sleep 0.25
4748

4849
((i=i+1))
49-
if [ "$i" -eq 120 ]; then
50+
if [ "$i" -eq 200 ]; then
5051
echo " Timeout!" >&2
5152
exit 0
5253
fi
5354
done
5455
echo "Done!"
5556
}
5657

58+
mkdir -p ./.devnet
59+
60+
if [ ! -f ./.devnet/rollup.json ]; then
61+
GENESIS_TIMESTAMP=$(date +%s | xargs printf "0x%x")
62+
else
63+
GENESIS_TIMESTAMP=$(jq '.genesis.l2_time' < .devnet/rollup.json)
64+
fi
65+
5766
# Regenerate the L1 genesis file if necessary. The existence of the genesis
5867
# file is used to determine if we need to recreate the devnet's state folder.
5968
if [ ! -f ./.devnet/genesis-l1.json ]; then
6069
echo "Regenerating L1 genesis."
61-
mkdir -p ./.devnet
62-
GENESIS_TIMESTAMP=$(date +%s | xargs printf "0x%x")
63-
jq ". | .timestamp = \"$GENESIS_TIMESTAMP\" " < ./ops-bedrock/genesis-l1.json > ./.devnet/genesis-l1.json
64-
else
65-
GENESIS_TIMESTAMP=$(jq -r '.timestamp' < ./.devnet/genesis-l1.json)
70+
(
71+
cd $CONTRACTS_BEDROCK
72+
L2OO_STARTING_BLOCK_TIMESTAMP=$GENESIS_TIMESTAMP npx hardhat genesis-l1 \
73+
--outfile genesis-l1.json
74+
mv genesis-l1.json ../../.devnet/genesis-l1.json
75+
)
6676
fi
6777

6878
# Bring up L1.
@@ -75,43 +85,27 @@ fi
7585
)
7686

7787
# Deploy contracts using Hardhat.
78-
if [ ! -f $CONTRACTS_BEDROCK/deployments/devnetL1/OptimismPortal.json ]; then
79-
echo "Deploying contracts."
88+
if [ ! -d $CONTRACTS_BEDROCK/deployments/$NETWORK ]; then
8089
(
90+
echo "Deploying contracts."
8191
cd $CONTRACTS_BEDROCK
82-
L2OO_STARTING_BLOCK_TIMESTAMP=$GENESIS_TIMESTAMP yarn hardhat --network devnetL1 deploy
92+
L2OO_STARTING_BLOCK_TIMESTAMP=$GENESIS_TIMESTAMP yarn hardhat --network $NETWORK deploy
8393
)
8494
else
8595
echo "Contracts already deployed, skipping."
8696
fi
8797

88-
function get_deployed_bytecode() {
89-
echo $(jq -r .deployedBytecode $CONTRACTS_BEDROCK/artifacts/contracts/$1)
90-
}
91-
92-
# Pull out the necessary bytecode/addresses from the artifacts/deployments.
93-
L2_TO_L1_MESSAGE_PASSER_BYTECODE=$(get_deployed_bytecode L2/L2ToL1MessagePasser.sol/L2ToL1MessagePasser.json)
94-
L2_CROSS_DOMAIN_MESSENGER_BYTECODE=$(get_deployed_bytecode L2/L2CrossDomainMessenger.sol/L2CrossDomainMessenger.json)
95-
OPTIMISM_MINTABLE_TOKEN_FACTORY_BYTECODE=$(get_deployed_bytecode universal/OptimismMintableTokenFactory.sol/OptimismMintableTokenFactory.json)
96-
L2_STANDARD_BRIDGE_BYTECODE=$(get_deployed_bytecode L2/L2StandardBridge.sol/L2StandardBridge.json)
97-
L1_BLOCK_INFO_BYTECODE=$(get_deployed_bytecode L2/L1Block.sol/L1Block.json)
98-
99-
DEPOSIT_CONTRACT_ADDRESS=$(jq -r .address < $CONTRACTS_BEDROCK/deployments/devnetL1/OptimismPortal.json)
100-
L2OO_ADDRESS=$(jq -r .address < $CONTRACTS_BEDROCK/deployments/devnetL1/L2OutputOracle.json)
101-
102-
# Replace values in the L2 genesis file. It doesn't matter if this gets run every time,
103-
# since the replaced values will be the same.
104-
jq ". | .alloc.\"4200000000000000000000000000000000000015\".code = \"$L1_BLOCK_INFO_BYTECODE\"" < ./ops-bedrock/genesis-l2.json | \
105-
jq ". | .alloc.\"4200000000000000000000000000000000000015\".balance = \"0x0\"" | \
106-
jq ". | .alloc.\"4200000000000000000000000000000000000000\".code = \"$L2_TO_L1_MESSAGE_PASSER_BYTECODE\"" | \
107-
jq ". | .alloc.\"4200000000000000000000000000000000000000\".balance = \"0x0\"" | \
108-
jq ". | .alloc.\"4200000000000000000000000000000000000007\".code = \"$L2_CROSS_DOMAIN_MESSENGER_BYTECODE\"" | \
109-
jq ". | .alloc.\"4200000000000000000000000000000000000007\".balance = \"0x0\"" | \
110-
jq ". | .alloc.\"4200000000000000000000000000000000000012\".code = \"$OPTIMISM_MINTABLE_TOKEN_FACTORY_BYTECODE\"" | \
111-
jq ". | .alloc.\"4200000000000000000000000000000000000012\".balance = \"0x0\"" | \
112-
jq ". | .alloc.\"4200000000000000000000000000000000000010\".code = \"$L2_STANDARD_BRIDGE_BYTECODE\"" | \
113-
jq ". | .alloc.\"4200000000000000000000000000000000000010\".balance = \"0x0\"" | \
114-
jq ". | .timestamp = \"$GENESIS_TIMESTAMP\" " > ./.devnet/genesis-l2.json
98+
if [ ! -f ./.devnet/genesis-l2.json ]; then
99+
(
100+
echo "Creating L2 genesis file."
101+
cd $CONTRACTS_BEDROCK
102+
L2OO_STARTING_BLOCK_TIMESTAMP=$GENESIS_TIMESTAMP npx hardhat --network $NETWORK genesis-l2
103+
mv genesis.json ../../.devnet/genesis-l2.json
104+
echo "Created L2 genesis."
105+
)
106+
else
107+
echo "L2 genesis already exists."
108+
fi
115109

116110
# Bring up L2.
117111
(
@@ -122,40 +116,19 @@ jq ". | .alloc.\"4200000000000000000000000000000000000015\".code = \"$L1_BLOCK_I
122116
)
123117

124118
# Start putting together the rollup config.
125-
echo "Building rollup config..."
126-
127-
# Grab the L1 genesis. We can use cURL here to retry.
128-
L1_GENESIS=$(curl \
129-
--silent \
130-
--fail \
131-
--retry 10 \
132-
--retry-delay 2 \
133-
--retry-connrefused \
134-
-X POST \
135-
-H "Content-Type: application/json" \
136-
--data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x0", false],"id":1}' \
137-
$L1_URL)
138-
139-
# Grab the L2 genesis. We can use cURL here to retry.
140-
L2_GENESIS=$(curl \
141-
--silent \
142-
--fail \
143-
--retry 10 \
144-
--retry-delay 2 \
145-
--retry-connrefused \
146-
-X POST \
147-
-H "Content-Type: application/json" \
148-
--data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x0", false],"id":1}' \
149-
$L2_URL)
150-
151-
# Generate the rollup config.
152-
jq ". | .genesis.l1.hash = \"$(echo $L1_GENESIS | jq -r '.result.hash')\"" < ./ops-bedrock/rollup.json | \
153-
jq ". | .genesis.l2.hash = \"$(echo $L2_GENESIS | jq -r '.result.hash')\"" | \
154-
jq ". | .genesis.l2_time = $(echo $L2_GENESIS | jq -r '.result.timestamp' | xargs printf "%d")" | \
155-
jq ". | .deposit_contract_address = \"$DEPOSIT_CONTRACT_ADDRESS\"" > ./.devnet/rollup.json
156-
157-
158-
SEQUENCER_GENESIS_HASH="$(echo $L2_GENESIS | jq -r '.result.hash')"
119+
if [ ! -f ./.devnet/rollup.json ]; then
120+
(
121+
echo "Building rollup config..."
122+
cd $CONTRACTS_BEDROCK
123+
L2OO_STARTING_BLOCK_TIMESTAMP=$GENESIS_TIMESTAMP npx hardhat rollup-config --network $NETWORK
124+
mv rollup.json ../../.devnet/rollup.json
125+
)
126+
else
127+
echo "Rollup config already exists"
128+
fi
129+
130+
L2OO_ADDRESS=$(jq -r .address < $CONTRACTS_BEDROCK/deployments/$NETWORK/L2OutputOracleProxy.json)
131+
SEQUENCER_GENESIS_HASH="$(jq -r '.l2.hash' < .devnet/rollup.json)"
159132
SEQUENCER_BATCH_INBOX_ADDRESS="$(cat ./ops-bedrock/rollup.json | jq -r '.batch_inbox_address')"
160133

161134
# Bring up everything else.

0 commit comments

Comments
 (0)