diff --git a/Makefile b/Makefile index 101e7922d..afef4dec8 100644 --- a/Makefile +++ b/Makefile @@ -109,4 +109,8 @@ pr: # Set genesis from system contract source files genesis: - $(MAKE) -C crates/evm/src/evm/system_contracts genesis \ No newline at end of file + $(MAKE) -C crates/evm/src/evm/system_contracts genesis + +# Set production genesis from system contract source files +genesis-prod: + $(MAKE) -C crates/evm/src/evm/system_contracts genesis-prod \ No newline at end of file diff --git a/crates/evm/src/evm/system_contracts/Makefile b/crates/evm/src/evm/system_contracts/Makefile index 0d0df5522..5e237a9ae 100644 --- a/crates/evm/src/evm/system_contracts/Makefile +++ b/crates/evm/src/evm/system_contracts/Makefile @@ -5,4 +5,7 @@ help: ## Display this help message # Set genesis from system contract source files genesis: - forge script script/GenesisGenerator.s.sol:GenesisGenerator --ffi \ No newline at end of file + forge script script/GenesisGenerator.s.sol:GenesisGenerator --ffi + +genesis-prod: + forge script script/GenesisGenerator.s.sol:GenesisGenerator --ffi --sig "runProd()" \ No newline at end of file diff --git a/crates/evm/src/evm/system_contracts/script/GenesisGenerator.s.sol b/crates/evm/src/evm/system_contracts/script/GenesisGenerator.s.sol index 4a3e7ed07..fc64daaf7 100644 --- a/crates/evm/src/evm/system_contracts/script/GenesisGenerator.s.sol +++ b/crates/evm/src/evm/system_contracts/script/GenesisGenerator.s.sol @@ -52,9 +52,8 @@ contract GenesisGenerator is Script { uint160 PROXY_IMPL_OFFSET = uint160(0x0100000000000000000000000000000000000000); // uint160(address(proxy)) - uint160(address(impl)) // Owner of proxy admin - //! CHANGE THIS IN PRODUCTION TO THE INITIAL EOA OWNER - address internal owner = address(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266); - address internal feeRecipient = address(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266); + address internal owner; + address internal feeRecipient; address[] internal devAddresses = [ @@ -72,12 +71,26 @@ contract GenesisGenerator is Script { function run() public { + owner = address(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266); + feeRecipient = address(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266); dealBalanceToDevAddrs(); dealBalanceToBridge(); setProxyAdmin(); setContracts(); vm.dumpState("./state/genesis.json"); - generateEvmJson("./state/genesis.json", "./state/evm.json"); + generateEvmJson("./state/genesis.json", "./state/evm.json", false); + } + + function runProd() public { + owner = vm.envAddress("OWNER"); + feeRecipient = vm.envAddress("FEE_RECIPIENT"); + string memory defaultPath = "./state/evmProd.json"; + string memory copyPath = vm.envOr("PROD_JSON_PATH", defaultPath); + dealBalanceToBridge(); + setProxyAdmin(); + setContracts(); + vm.dumpState("./state/genesisProd.json"); + generateEvmJson("./state/genesisProd.json", copyPath, true); } function dealBalanceToDevAddrs() internal { @@ -140,11 +153,11 @@ contract GenesisGenerator is Script { vm.resetNonce(initProxyImpl); } - function generateEvmJson(string memory _genesisPath, string memory _evmPath) internal { + function generateEvmJson(string memory _genesisPath, string memory _evmPath, bool _isProd) internal { string[] memory commands = new string[](3); commands[0] = "bash"; commands[1] = "-c"; - commands[2] = string.concat("python3 ./script/GenesisToEvmJson.py ", _genesisPath, " ", _evmPath ); + commands[2] = string.concat("python3 ./script/GenesisToEvmJson.py ", _genesisPath, " ", _evmPath, " ", _isProd ? "true" : "false"); Process.run(commands, false); } } diff --git a/crates/evm/src/evm/system_contracts/script/GenesisToEvmJson.py b/crates/evm/src/evm/system_contracts/script/GenesisToEvmJson.py index 70e7d9f91..8174ab6c6 100644 --- a/crates/evm/src/evm/system_contracts/script/GenesisToEvmJson.py +++ b/crates/evm/src/evm/system_contracts/script/GenesisToEvmJson.py @@ -1,9 +1,12 @@ import json import sys +import os with open(sys.argv[1], "r") as file: data = json.load(file) +isProd = True if (sys.argv[3] == "true") else False + # Sort the data by key data = {k: data[k] for k in sorted(data)} @@ -20,7 +23,12 @@ evm_json = {} evm_json["data"] = new_data -evm_json["chain_id"] = 5655 +if not isProd: + evm_json["chain_id"] = 5655 +else: + if os.environ.get("CHAIN_ID") is None: + raise Exception("CHAIN_ID environment variable is not set") + evm_json["chain_id"] = os.getenv("CHAIN_ID") evm_json["limit_contract_code_size"] = None evm_json["spec"] = {"0": "SHANGHAI"} evm_json["coinbase"] = "0x3100000000000000000000000000000000000005" @@ -47,11 +55,12 @@ "../../../../../resources/test-data/integration-tests-low-max-l2-blocks-per-l1/evm.json" ] -for path in paths: - with open(path, "w") as file: - if path == "../../../../../resources/test-data/integration-tests-low-block-gas-limit/evm.json": - new_evm_json = evm_json.copy() - new_evm_json["block_gas_limit"] = 1500000 - json.dump(new_evm_json, file, indent=2) - continue - json.dump(evm_json, file, indent=2) \ No newline at end of file +if not isProd: + for path in paths: + with open(path, "w") as file: + if path == "../../../../../resources/test-data/integration-tests-low-block-gas-limit/evm.json": + new_evm_json = evm_json.copy() + new_evm_json["block_gas_limit"] = 1500000 + json.dump(new_evm_json, file, indent=2) + continue + json.dump(evm_json, file, indent=2) \ No newline at end of file