Skip to content

Commit c828635

Browse files
committed
contracts: Make L2 genesis script configurable
1 parent 384e2dc commit c828635

File tree

9 files changed

+103
-55
lines changed

9 files changed

+103
-55
lines changed

.circleci/config.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,25 +243,25 @@ jobs:
243243
- "packages/contracts-bedrock/tsconfig.tsbuildinfo"
244244
- "packages/contracts-bedrock/tsconfig.build.tsbuildinfo"
245245
- ".devnet/allocs-l1.json"
246-
- ".devnet/allocs-l2.json"
247246
- ".devnet/allocs-l2-delta.json"
248247
- ".devnet/allocs-l2-ecotone.json"
248+
- ".devnet/allocs-l2-fjord.json"
249249
- ".devnet/addresses.json"
250250
- ".devnet-l2oo/allocs-l1.json"
251251
- ".devnet-l2oo/addresses.json"
252-
- ".devnet-l2oo/allocs-l2.json"
253252
- ".devnet-l2oo/allocs-l2-delta.json"
254253
- ".devnet-l2oo/allocs-l2-ecotone.json"
254+
- ".devnet-l2oo/allocs-l2-fjord.json"
255255
- ".devnet-plasma/allocs-l1.json"
256256
- ".devnet-plasma/addresses.json"
257-
- ".devnet-plasma/allocs-l2.json"
258257
- ".devnet-plasma/allocs-l2-delta.json"
259258
- ".devnet-plasma/allocs-l2-ecotone.json"
259+
- ".devnet-plasma/allocs-l2-fjord.json"
260260
- ".devnet-plasma-generic/allocs-l1.json"
261261
- ".devnet-plasma-generic/addresses.json"
262-
- ".devnet-plasma-generic/allocs-l2.json"
263262
- ".devnet-plasma-generic/allocs-l2-delta.json"
264263
- ".devnet-plasma-generic/allocs-l2-ecotone.json"
264+
- ".devnet-plasma-generic/allocs-l2-fjord.json"
265265
- "packages/contracts-bedrock/deploy-config/devnetL1.json"
266266
- "packages/contracts-bedrock/deployments/devnetL1"
267267
- notify-failures-on-develop
@@ -1000,9 +1000,9 @@ jobs:
10001000
name: Load devnet-allocs
10011001
command: |
10021002
mkdir -p .devnet
1003-
cp /tmp/workspace/.devnet<<parameters.variant>>/allocs-l2.json .devnet/allocs-l2.json
10041003
cp /tmp/workspace/.devnet<<parameters.variant>>/allocs-l2-delta.json .devnet/allocs-l2-delta.json
10051004
cp /tmp/workspace/.devnet<<parameters.variant>>/allocs-l2-ecotone.json .devnet/allocs-l2-ecotone.json
1005+
cp /tmp/workspace/.devnet<<parameters.variant>>/allocs-l2-fjord.json .devnet/allocs-l2-fjord.json
10061006
cp /tmp/workspace/.devnet<<parameters.variant>>/allocs-l1.json .devnet/allocs-l1.json
10071007
cp /tmp/workspace/.devnet<<parameters.variant>>/addresses.json .devnet/addresses.json
10081008
cp /tmp/workspace/packages/contracts-bedrock/deploy-config/devnetL1.json packages/contracts-bedrock/deploy-config/devnetL1.json
@@ -1248,9 +1248,9 @@ jobs:
12481248
- persist_to_workspace:
12491249
root: .
12501250
paths:
1251-
- ".devnet/allocs-l2.json"
12521251
- ".devnet/allocs-l2-delta.json"
12531252
- ".devnet/allocs-l2-ecotone.json"
1253+
- ".devnet/allocs-l2-fjord.json"
12541254
- ".devnet/allocs-l1.json"
12551255
- ".devnet/addresses.json"
12561256
- "packages/contracts-bedrock/deploy-config/devnetL1.json"

bedrock-devnet/devnet/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
log = logging.getLogger()
2828

29+
# Global constants
30+
FORKS = ["delta", "ecotone", "fjord"]
31+
2932
# Global environment variables
3033
DEVNET_NO_BUILD = os.getenv('DEVNET_NO_BUILD') == "true"
3134
DEVNET_L2OO = os.getenv('DEVNET_L2OO') == "true"
@@ -171,9 +174,9 @@ def devnet_l2_allocs(paths):
171174

172175
# For the previous forks, and the latest fork (default, thus empty prefix),
173176
# move the forge-dumps into place as .devnet allocs.
174-
for suffix in ["-delta", "-ecotone", ""]:
175-
input_path = pjoin(paths.contracts_bedrock_dir, f"state-dump-901{suffix}.json")
176-
output_path = pjoin(paths.devnet_dir, f'allocs-l2{suffix}.json')
177+
for fork in FORKS:
178+
input_path = pjoin(paths.contracts_bedrock_dir, f"state-dump-901-{fork}.json")
179+
output_path = pjoin(paths.devnet_dir, f'allocs-l2-{fork}.json')
177180
shutil.move(src=input_path, dst=output_path)
178181
log.info("Generated L2 allocs: "+output_path)
179182

@@ -218,7 +221,7 @@ def devnet_deploy(paths):
218221
log.info('L2 genesis and rollup configs already generated.')
219222
else:
220223
log.info('Generating L2 genesis and rollup configs.')
221-
l2_allocs_path = pjoin(paths.devnet_dir, 'allocs-l2.json')
224+
l2_allocs_path = pjoin(paths.devnet_dir, f'allocs-l2-{FORKS[-1]}.json')
222225
if os.path.exists(l2_allocs_path) == False or DEVNET_L2OO == True:
223226
# Also regenerate if L2OO.
224227
# The L2OO flag may affect the L1 deployments addresses, which may affect the L2 genesis.

op-chain-ops/genesis/layer_two.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type L2AllocsMode string
2424
const (
2525
L2AllocsDelta L2AllocsMode = "delta"
2626
L2AllocsEcotone L2AllocsMode = "ecotone"
27-
L2AllocsFjord L2AllocsMode = "" // the default in solidity scripting / testing
27+
L2AllocsFjord L2AllocsMode = "fjord"
2828
)
2929

3030
var (

op-e2e/config/init.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,7 @@ func init() {
113113
}
114114
l2Allocs = make(map[genesis.L2AllocsMode]*genesis.ForgeAllocs)
115115
mustL2Allocs := func(mode genesis.L2AllocsMode) {
116-
name := "allocs-l2"
117-
if mode != "" {
118-
name += "-" + string(mode)
119-
}
116+
name := "allocs-l2-" + string(mode)
120117
allocs, err := genesis.LoadForgeAllocs(filepath.Join(l2AllocsDir, name+".json"))
121118
if err != nil {
122119
panic(err)

packages/contracts-bedrock/scripts/Config.sol

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@ pragma solidity ^0.8.0;
33

44
import { Vm, VmSafe } from "forge-std/Vm.sol";
55

6+
/// @notice Enum representing different ways of outputting genesis allocs.
7+
/// @custom:value NONE No output, used in internal tests.
8+
/// @custom:value LATEST Output allocs only for latest fork.
9+
/// @custom:value ALL Output allocs for all intermediary forks.
10+
enum OutputMode {
11+
NONE,
12+
LATEST,
13+
ALL
14+
}
15+
16+
/// @notice Enum of forks available for selection when generating genesis allocs.
17+
enum Fork {
18+
DELTA,
19+
ECOTONE,
20+
FJORD
21+
}
22+
23+
/// @notice Always points to the latest fork.
24+
Fork constant LATEST_FORK = Fork.FJORD;
25+
626
/// @title Config
727
/// @notice Contains all env var based config. Add any new env var parsing to this file
828
/// to ensure that all config is in a single place.
@@ -67,4 +87,36 @@ library Config {
6787
function drippieOwnerPrivateKey() internal view returns (uint256 _env) {
6888
_env = vm.envUint("DRIPPIE_OWNER_PRIVATE_KEY");
6989
}
90+
91+
/// @notice Returns the OutputMode for genesis allocs generation.
92+
function outputMode() internal view returns (OutputMode) {
93+
string memory modeStr = vm.envOr("OUTPUT_MODE", string("all"));
94+
bytes32 modeHash = keccak256(bytes(modeStr));
95+
if (modeHash == keccak256(bytes("none"))) {
96+
return OutputMode.NONE;
97+
} else if (modeHash == keccak256(bytes("latest"))) {
98+
return OutputMode.LATEST;
99+
} else if (modeHash == keccak256(bytes("all"))) {
100+
return OutputMode.ALL;
101+
} else {
102+
revert(string.concat("Config: unknown output mode: ", modeStr));
103+
}
104+
}
105+
106+
/// @notice Returns the latest fork to use for genesis allocs generation.
107+
function fork() internal view returns (Fork) {
108+
string memory forkStr = vm.envOr("FORK", string("latest"));
109+
bytes32 forkHash = keccak256(bytes(forkStr));
110+
if (forkHash == keccak256(bytes("latest"))) {
111+
return LATEST_FORK;
112+
} else if (forkHash == keccak256(bytes("delta"))) {
113+
return Fork.DELTA;
114+
} else if (forkHash == keccak256(bytes("ecotone"))) {
115+
return Fork.ECOTONE;
116+
} else if (forkHash == keccak256(bytes("fjord"))) {
117+
return Fork.FJORD;
118+
} else {
119+
revert(string.concat("Config: unknown fork: ", forkStr));
120+
}
121+
}
70122
}

packages/contracts-bedrock/scripts/L2Genesis.s.sol

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Script } from "forge-std/Script.sol";
55
import { console2 as console } from "forge-std/console2.sol";
66
import { Deployer } from "scripts/Deployer.sol";
77

8-
import { Config } from "scripts/Config.sol";
8+
import { Config, OutputMode, Fork, LATEST_FORK } from "scripts/Config.sol";
99
import { Artifacts } from "scripts/Artifacts.s.sol";
1010
import { DeployConfig } from "scripts/DeployConfig.s.sol";
1111
import { Predeploys } from "src/libraries/Predeploys.sol";
@@ -37,20 +37,6 @@ struct L1Dependencies {
3737
address payable l1ERC721BridgeProxy;
3838
}
3939

40-
/// @notice Enum representing different ways of outputting genesis allocs.
41-
/// @custom:value DEFAULT_LATEST Represents only latest L2 allocs, written to output path.
42-
/// @custom:value LOCAL_LATEST Represents latest L2 allocs, not output anywhere, but kept in-process.
43-
/// @custom:value LOCAL_ECOTONE Represents Ecotone-upgrade L2 allocs, not output anywhere, but kept in-process.
44-
/// @custom:value LOCAL_DELTA Represents Delta-upgrade L2 allocs, not output anywhere, but kept in-process.
45-
/// @custom:value OUTPUT_ALL Represents creation of one L2 allocs file for every upgrade.
46-
enum OutputMode {
47-
DEFAULT_LATEST,
48-
LOCAL_LATEST,
49-
LOCAL_ECOTONE,
50-
LOCAL_DELTA,
51-
OUTPUT_ALL
52-
}
53-
5440
/// @title L2Genesis
5541
/// @notice Generates the genesis state for the L2 network.
5642
/// The following safety invariants are used when setting state:
@@ -120,7 +106,7 @@ contract L2Genesis is Deployer {
120106
/// Sets the precompiles, proxies, and the implementation accounts to be `vm.dumpState`
121107
/// to generate a L2 genesis alloc.
122108
function runWithStateDump() public {
123-
runWithOptions(OutputMode.DEFAULT_LATEST, artifactDependencies());
109+
runWithOptions(Config.outputMode(), Config.fork(), artifactDependencies());
124110
}
125111

126112
/// @notice Alias for `runWithStateDump` so that no `--sig` needs to be specified.
@@ -130,11 +116,17 @@ contract L2Genesis is Deployer {
130116

131117
/// @notice This is used by op-e2e to have a version of the L2 allocs for each upgrade.
132118
function runWithAllUpgrades() public {
133-
runWithOptions(OutputMode.OUTPUT_ALL, artifactDependencies());
119+
runWithOptions(OutputMode.ALL, LATEST_FORK, artifactDependencies());
120+
}
121+
122+
/// @notice This is used by foundry tests to enable the latest fork with the
123+
/// given L1 dependencies.
124+
function runWithLatestLocal(L1Dependencies memory _l1Dependencies) public {
125+
runWithOptions(OutputMode.NONE, LATEST_FORK, _l1Dependencies);
134126
}
135127

136128
/// @notice Build the L2 genesis.
137-
function runWithOptions(OutputMode _mode, L1Dependencies memory _l1Dependencies) public {
129+
function runWithOptions(OutputMode _mode, Fork _fork, L1Dependencies memory _l1Dependencies) public {
138130
vm.startPrank(deployer);
139131
vm.chainId(cfg.l2ChainID());
140132

@@ -147,28 +139,29 @@ contract L2Genesis is Deployer {
147139
}
148140
vm.stopPrank();
149141

150-
// Genesis is "complete" at this point, but some hardfork activation steps remain.
151-
// Depending on the "Output Mode" we perform the activations and output the necessary state dumps.
152-
if (_mode == OutputMode.LOCAL_DELTA) {
153-
return;
154-
}
155-
if (_mode == OutputMode.OUTPUT_ALL) {
142+
if (_mode == OutputMode.ALL || _fork == Fork.DELTA && _mode == OutputMode.LATEST) {
156143
writeGenesisAllocs(Config.stateDumpPath("-delta"));
157144
}
145+
if (_fork == Fork.DELTA) {
146+
return;
147+
}
158148

159149
activateEcotone();
160150

161-
if (_mode == OutputMode.LOCAL_ECOTONE) {
162-
return;
163-
}
164-
if (_mode == OutputMode.OUTPUT_ALL) {
151+
if (_mode == OutputMode.ALL || _fork == Fork.ECOTONE && _mode == OutputMode.LATEST) {
165152
writeGenesisAllocs(Config.stateDumpPath("-ecotone"));
166153
}
154+
if (_fork == Fork.ECOTONE) {
155+
return;
156+
}
167157

168158
activateFjord();
169159

170-
if (_mode == OutputMode.OUTPUT_ALL || _mode == OutputMode.DEFAULT_LATEST) {
171-
writeGenesisAllocs(Config.stateDumpPath(""));
160+
if (_mode == OutputMode.ALL || _fork == Fork.FJORD && _mode == OutputMode.LATEST) {
161+
writeGenesisAllocs(Config.stateDumpPath("-fjord"));
162+
}
163+
if (_fork == Fork.FJORD) {
164+
return;
172165
}
173166
}
174167

packages/contracts-bedrock/test/L2/GasPriceOracle.t.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity 0.8.15;
33

44
// Testing utilities
55
import { CommonTest } from "test/setup/CommonTest.sol";
6-
import { OutputMode } from "scripts/L2Genesis.s.sol";
6+
import { Fork } from "scripts/Config.sol";
77

88
// Libraries
99
import { Encoding } from "src/libraries/Encoding.sol";
@@ -39,7 +39,7 @@ contract GasPriceOracleBedrock_Test is GasPriceOracle_Test {
3939
/// @dev Sets up the test suite.
4040
function setUp() public virtual override {
4141
// The gasPriceOracle tests rely on an L2 genesis that is not past Ecotone.
42-
l2OutputMode = OutputMode.LOCAL_DELTA;
42+
l2Fork = Fork.DELTA;
4343
super.setUp();
4444
assertEq(gasPriceOracle.isEcotone(), false);
4545

@@ -120,7 +120,7 @@ contract GasPriceOracleBedrock_Test is GasPriceOracle_Test {
120120
contract GasPriceOracleEcotone_Test is GasPriceOracle_Test {
121121
/// @dev Sets up the test suite.
122122
function setUp() public virtual override {
123-
l2OutputMode = OutputMode.LOCAL_ECOTONE; // activate ecotone
123+
l2Fork = Fork.ECOTONE;
124124
super.setUp();
125125
assertEq(gasPriceOracle.isEcotone(), true);
126126

@@ -213,7 +213,7 @@ contract GasPriceOracleEcotone_Test is GasPriceOracle_Test {
213213
contract GasPriceOracleFjordActive_Test is GasPriceOracle_Test {
214214
/// @dev Sets up the test suite.
215215
function setUp() public virtual override {
216-
l2OutputMode = OutputMode.LOCAL_LATEST; // activate fjord
216+
l2Fork = Fork.FJORD;
217217
super.setUp();
218218

219219
bytes memory calldataPacked = Encoding.encodeSetL1BlockValuesEcotone(

packages/contracts-bedrock/test/L2Genesis.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity 0.8.15;
33

44
import { Test } from "forge-std/Test.sol";
5-
import { L2Genesis, OutputMode, L1Dependencies } from "scripts/L2Genesis.s.sol";
5+
import { L2Genesis, L1Dependencies } from "scripts/L2Genesis.s.sol";
66
import { Predeploys } from "src/libraries/Predeploys.sol";
77
import { Constants } from "src/libraries/Constants.sol";
88
import { Process } from "scripts/libraries/Process.sol";
@@ -181,7 +181,7 @@ contract L2GenesisTest is Test {
181181
/// @notice Tests the number of accounts in the genesis setup
182182
function _test_allocs_size(string memory _path) internal {
183183
genesis.cfg().setFundDevAccounts(false);
184-
genesis.runWithOptions(OutputMode.LOCAL_LATEST, _dummyL1Deps());
184+
genesis.runWithLatestLocal(_dummyL1Deps());
185185
genesis.writeGenesisAllocs(_path);
186186

187187
uint256 expected = 0;

packages/contracts-bedrock/test/setup/Setup.sol

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ import { DelayedWETH } from "src/dispute/weth/DelayedWETH.sol";
2525
import { AnchorStateRegistry } from "src/dispute/AnchorStateRegistry.sol";
2626
import { L1CrossDomainMessenger } from "src/L1/L1CrossDomainMessenger.sol";
2727
import { DeployConfig } from "scripts/DeployConfig.s.sol";
28+
import { Fork, LATEST_FORK } from "scripts/Config.sol";
2829
import { Deploy } from "scripts/Deploy.s.sol";
29-
import { L2Genesis, L1Dependencies, OutputMode } from "scripts/L2Genesis.s.sol";
30+
import { L2Genesis, L1Dependencies } from "scripts/L2Genesis.s.sol";
31+
import { OutputMode, Fork } from "scripts/Config.sol";
3032
import { L2OutputOracle } from "src/L1/L2OutputOracle.sol";
3133
import { ProtocolVersions } from "src/L1/ProtocolVersions.sol";
3234
import { SystemConfig } from "src/L1/SystemConfig.sol";
@@ -57,7 +59,7 @@ contract Setup {
5759
L2Genesis(address(uint160(uint256(keccak256(abi.encode("optimism.l2genesis"))))));
5860

5961
// @notice Allows users of Setup to override what L2 genesis is being created.
60-
OutputMode l2OutputMode = OutputMode.LOCAL_LATEST;
62+
Fork l2Fork = LATEST_FORK;
6163

6264
OptimismPortal optimismPortal;
6365
OptimismPortal2 optimismPortal2;
@@ -175,9 +177,10 @@ contract Setup {
175177

176178
/// @dev Sets up the L2 contracts. Depends on `L1()` being called first.
177179
function L2() public {
178-
console.log("Setup: creating L2 genesis, with output mode %d", uint256(l2OutputMode));
180+
console.log("Setup: creating L2 genesis with fork %d", uint256(l2Fork));
179181
l2Genesis.runWithOptions(
180-
l2OutputMode,
182+
OutputMode.NONE,
183+
l2Fork,
181184
L1Dependencies({
182185
l1CrossDomainMessengerProxy: payable(address(l1CrossDomainMessenger)),
183186
l1StandardBridgeProxy: payable(address(l1StandardBridge)),

0 commit comments

Comments
 (0)