Skip to content

Commit

Permalink
Add genesis production mode
Browse files Browse the repository at this point in the history
  • Loading branch information
okkothejawa committed Jul 19, 2024
1 parent d1fea9d commit 10bbd5f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 17 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,8 @@ pr:

# Set genesis from system contract source files
genesis:
$(MAKE) -C crates/evm/src/evm/system_contracts genesis
$(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
5 changes: 4 additions & 1 deletion crates/evm/src/evm/system_contracts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
forge script script/GenesisGenerator.s.sol:GenesisGenerator --ffi

genesis-prod:
forge script script/GenesisGenerator.s.sol:GenesisGenerator --ffi --sig "runProd()"
25 changes: 19 additions & 6 deletions crates/evm/src/evm/system_contracts/script/GenesisGenerator.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
[
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
}
}
27 changes: 18 additions & 9 deletions crates/evm/src/evm/system_contracts/script/GenesisToEvmJson.py
Original file line number Diff line number Diff line change
@@ -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)}

Expand All @@ -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"
Expand All @@ -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)
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)

0 comments on commit 10bbd5f

Please sign in to comment.