Skip to content

feat: e2e devnet deployment scripts #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
af12443
feat: add deterministic scripts
yiweichi Apr 15, 2025
b94355e
remove volume files
yiweichi Apr 15, 2025
c1bfcf5
remove .DS_Store
yiweichi Apr 15, 2025
cfa25e7
update .gitignore
yiweichi Apr 15, 2025
06a8c77
fix: deploy issues
yiweichi Apr 16, 2025
7811cf2
clean config-contracts
yiweichi Apr 16, 2025
9450217
add .gitignore
yiweichi Apr 16, 2025
6d2f45b
add .gitignore
yiweichi Apr 16, 2025
63210c0
add .gitignore
yiweichi Apr 16, 2025
ad666aa
update .gitignore
yiweichi Apr 16, 2025
10226ae
fix: genesis path
yiweichi Apr 16, 2025
4268404
remove unused files
yiweichi Apr 16, 2025
4d47fb3
ignore scripts
yiweichi Apr 16, 2025
023f28e
add gas oracle
yiweichi Apr 16, 2025
a1f9df3
update config.toml
yiweichi Apr 16, 2025
c9bdd18
update config.toml
yiweichi Apr 16, 2025
df97231
add config-contracts.toml
yiweichi Apr 16, 2025
08adccd
update verifier
yiweichi Apr 16, 2025
b6fcc41
feat: remove bridge history config
yiweichi Apr 21, 2025
97c7f4f
rename genesis.json
yiweichi Apr 21, 2025
6ee59bc
rm balance checker
yiweichi Apr 21, 2025
355de0c
fix: generate genesis
yiweichi Apr 21, 2025
1268104
feat: init system config
yiweichi Apr 21, 2025
320d2c4
feat: reset config file paths
yiweichi Apr 21, 2025
f44e345
feat: reset config file paths
yiweichi Apr 21, 2025
929dbeb
feat: reset config file paths
yiweichi Apr 21, 2025
c0449dd
fix: path
yiweichi Apr 21, 2025
2922f69
add contract-config template
yiweichi Apr 22, 2025
0970ab9
fix: system config init check
yiweichi Apr 22, 2025
70d1cd2
fix: system config signer address
yiweichi Apr 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ broadcast

# Visual Studio Code
.vscode

# OS
.DS_Store

# config
scripts/deterministic/config/config-contracts.toml
14 changes: 12 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ optimizer = true # enable or disabl
optimizer_runs = 200 # the number of optimizer runs
verbosity = 2 # the verbosity of tests
ignored_error_codes = [] # a list of ignored solc error codes
fuzz_runs = 256 # the number of fuzz runs for tests
ffi = false # whether to enable ffi or not
fuzz_runs = 256 # the number of fuzz runs for test
sender = '0x00a329c0648769a73afac7f9381e08fb43dbea72' # the address of `msg.sender` in tests
tx_origin = '0x00a329c0648769a73afac7f9381e08fb43dbea72' # the address of `tx.origin` in tests
initial_balance = '0xffffffffffffffffffffffff' # the initial balance of the test contract
Expand All @@ -28,3 +27,14 @@ block_timestamp = 0 # the value of `bl
block_difficulty = 0 # the value of `block.difficulty` in tests

gas_reports = ["L2GasPriceOracle"]

# remove bytecode hash for reliable deterministic addresses
bytecode_hash = 'none'

# file system permissions
ffi = true

fs_permissions = [
{ access='read-write', path='./scripts/deterministic/config' },
{ access='read-write', path='../../config' },
]
226 changes: 226 additions & 0 deletions scripts/deterministic/Configuration.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.24;

import {Script} from "forge-std/Script.sol";
import {VmSafe} from "forge-std/Vm.sol";
import {stdToml} from "forge-std/StdToml.sol";

import {CONFIG_PATH, CONFIG_CONTRACTS_PATH, CONFIG_CONTRACTS_TEMPLATE_PATH} from "./Constants.sol";

/// @notice Configuration allows inheriting contracts to read the TOML configuration file.
abstract contract Configuration is Script {
using stdToml for string;

/*******************
* State variables *
*******************/

string internal cfg;
string internal contractsCfg;

/****************************
* Configuration parameters *
****************************/

// general
string internal L1_RPC_ENDPOINT;
string internal L2_RPC_ENDPOINT;

string internal CHAIN_NAME_L1;
string internal CHAIN_NAME_L2;
uint64 internal CHAIN_ID_L1;
uint64 internal CHAIN_ID_L2;

uint256 internal MAX_TX_IN_CHUNK;
uint256 internal MAX_BLOCK_IN_CHUNK;
uint256 internal MAX_BATCH_IN_BUNDLE;
uint256 internal MAX_L1_MESSAGE_GAS_LIMIT;

uint256 internal L1_CONTRACT_DEPLOYMENT_BLOCK;

bool internal TEST_ENV_MOCK_FINALIZE_ENABLED;
uint256 internal TEST_ENV_MOCK_FINALIZE_TIMEOUT_SEC;

// accounts
uint256 internal DEPLOYER_PRIVATE_KEY;
uint256 internal L1_COMMIT_SENDER_PRIVATE_KEY;
uint256 internal L1_FINALIZE_SENDER_PRIVATE_KEY;
uint256 internal L1_GAS_ORACLE_SENDER_PRIVATE_KEY;
uint256 internal L2_GAS_ORACLE_SENDER_PRIVATE_KEY;

address internal DEPLOYER_ADDR;
address internal L1_COMMIT_SENDER_ADDR;
address internal L1_FINALIZE_SENDER_ADDR;
address internal L1_GAS_ORACLE_SENDER_ADDR;
address internal L2_GAS_ORACLE_SENDER_ADDR;

address internal OWNER_ADDR;

address internal L2GETH_SIGNER_ADDRESS;

// db
string internal ROLLUP_EXPLORER_BACKEND_DB_CONNECTION_STRING;

// genesis
uint256 internal L2_MAX_ETH_SUPPLY;
uint256 internal L2_DEPLOYER_INITIAL_BALANCE;
uint256 internal L2_SCROLL_MESSENGER_INITIAL_BALANCE;

// contracts
string internal DEPLOYMENT_SALT;

address internal L1_FEE_VAULT_ADDR;

// coordinator
string internal CHUNK_COLLECTION_TIME_SEC;
string internal BATCH_COLLECTION_TIME_SEC;
string internal BUNDLE_COLLECTION_TIME_SEC;
string internal COORDINATOR_JWT_SECRET_KEY;

// frontend
string internal EXTERNAL_RPC_URI_L1;
string internal EXTERNAL_RPC_URI_L2;
string internal BRIDGE_API_URI;
string internal ROLLUPSCAN_API_URI;
string internal EXTERNAL_EXPLORER_URI_L1;
string internal EXTERNAL_EXPLORER_URI_L2;
string internal ADMIN_SYSTEM_DASHBOARD_URI;
string internal GRAFANA_URI;

/**********************
* Internal interface *
**********************/

function readConfig() internal {
if (!vm.exists(CONFIG_CONTRACTS_PATH)) {
string memory template = vm.readFile(CONFIG_CONTRACTS_TEMPLATE_PATH);
vm.writeFile(CONFIG_CONTRACTS_PATH, template);
}

cfg = vm.readFile(CONFIG_PATH);
contractsCfg = vm.readFile(CONFIG_CONTRACTS_PATH);

CHAIN_ID_L1 = uint64(cfg.readUint(".general.CHAIN_ID_L1"));
CHAIN_ID_L2 = uint64(cfg.readUint(".general.CHAIN_ID_L2"));

MAX_TX_IN_CHUNK = cfg.readUint(".rollup.MAX_TX_IN_CHUNK");
MAX_BLOCK_IN_CHUNK = cfg.readUint(".rollup.MAX_BLOCK_IN_CHUNK");
MAX_BATCH_IN_BUNDLE = cfg.readUint(".rollup.MAX_BATCH_IN_BUNDLE");
MAX_L1_MESSAGE_GAS_LIMIT = cfg.readUint(".rollup.MAX_L1_MESSAGE_GAS_LIMIT");

L1_CONTRACT_DEPLOYMENT_BLOCK = cfg.readUint(".general.L1_CONTRACT_DEPLOYMENT_BLOCK");

TEST_ENV_MOCK_FINALIZE_ENABLED = cfg.readBool(".rollup.TEST_ENV_MOCK_FINALIZE_ENABLED");
TEST_ENV_MOCK_FINALIZE_TIMEOUT_SEC = cfg.readUint(".rollup.TEST_ENV_MOCK_FINALIZE_TIMEOUT_SEC");

DEPLOYER_PRIVATE_KEY = cfg.readUint(".accounts.DEPLOYER_PRIVATE_KEY");
L1_COMMIT_SENDER_PRIVATE_KEY = cfg.readUint(".accounts.L1_COMMIT_SENDER_PRIVATE_KEY");
L1_FINALIZE_SENDER_PRIVATE_KEY = cfg.readUint(".accounts.L1_FINALIZE_SENDER_PRIVATE_KEY");
L1_GAS_ORACLE_SENDER_PRIVATE_KEY = cfg.readUint(".accounts.L1_GAS_ORACLE_SENDER_PRIVATE_KEY");
L2_GAS_ORACLE_SENDER_PRIVATE_KEY = cfg.readUint(".accounts.L2_GAS_ORACLE_SENDER_PRIVATE_KEY");

DEPLOYER_ADDR = cfg.readAddress(".accounts.DEPLOYER_ADDR");
L1_COMMIT_SENDER_ADDR = cfg.readAddress(".accounts.L1_COMMIT_SENDER_ADDR");
L1_FINALIZE_SENDER_ADDR = cfg.readAddress(".accounts.L1_FINALIZE_SENDER_ADDR");
L1_GAS_ORACLE_SENDER_ADDR = cfg.readAddress(".accounts.L1_GAS_ORACLE_SENDER_ADDR");
L2_GAS_ORACLE_SENDER_ADDR = cfg.readAddress(".accounts.L2_GAS_ORACLE_SENDER_ADDR");

OWNER_ADDR = cfg.readAddress(".accounts.OWNER_ADDR");

L2GETH_SIGNER_ADDRESS = cfg.readAddress(".sequencer.L2GETH_SIGNER_ADDRESS");

L2_MAX_ETH_SUPPLY = cfg.readUint(".genesis.L2_MAX_ETH_SUPPLY");
L2_DEPLOYER_INITIAL_BALANCE = cfg.readUint(".genesis.L2_DEPLOYER_INITIAL_BALANCE");
L2_SCROLL_MESSENGER_INITIAL_BALANCE = L2_MAX_ETH_SUPPLY - L2_DEPLOYER_INITIAL_BALANCE;

DEPLOYMENT_SALT = cfg.readString(".contracts.DEPLOYMENT_SALT");

L1_FEE_VAULT_ADDR = cfg.readAddress(".contracts.L1_FEE_VAULT_ADDR");

CHUNK_COLLECTION_TIME_SEC = cfg.readString(".coordinator.CHUNK_COLLECTION_TIME_SEC");
BATCH_COLLECTION_TIME_SEC = cfg.readString(".coordinator.BATCH_COLLECTION_TIME_SEC");
BUNDLE_COLLECTION_TIME_SEC = cfg.readString(".coordinator.BUNDLE_COLLECTION_TIME_SEC");
COORDINATOR_JWT_SECRET_KEY = cfg.readString(".coordinator.COORDINATOR_JWT_SECRET_KEY");

runSanityCheck();
}

/// @dev Ensure that `addr` is not the zero address.
/// This helps catch bugs arising from incorrect deployment order.
function notnull(address addr) internal pure returns (address) {
require(addr != address(0), "null address");
return addr;
}

function tryGetOverride(string memory name) internal returns (address) {
address addr;
string memory key;
if (keccak256(abi.encodePacked(name)) == keccak256(abi.encodePacked("L1_GAS_TOKEN"))) {
key = string(abi.encodePacked(".gas-token.", name));
} else {
key = string(abi.encodePacked(".contracts.overrides.", name));
}

if (!vm.keyExistsToml(cfg, key)) {
return address(0);
}

addr = cfg.readAddress(key);

if (addr.code.length == 0) {
(VmSafe.CallerMode callerMode, , ) = vm.readCallers();

// if we're ready to start broadcasting transactions, then we
// must ensure that the override contract has been deployed.
if (callerMode == VmSafe.CallerMode.Broadcast || callerMode == VmSafe.CallerMode.RecurrentBroadcast) {
revert(
string(
abi.encodePacked(
"[ERROR] override ",
name,
" = ",
vm.toString(addr),
" not deployed in broadcast mode"
)
)
);
}
}

return addr;
}

/*********************
* Private functions *
*********************/

function runSanityCheck() private view {
verifyAccount("DEPLOYER", DEPLOYER_PRIVATE_KEY, DEPLOYER_ADDR);
verifyAccount("L1_COMMIT_SENDER", L1_COMMIT_SENDER_PRIVATE_KEY, L1_COMMIT_SENDER_ADDR);
verifyAccount("L1_FINALIZE_SENDER", L1_FINALIZE_SENDER_PRIVATE_KEY, L1_FINALIZE_SENDER_ADDR);
verifyAccount("L1_GAS_ORACLE_SENDER", L1_GAS_ORACLE_SENDER_PRIVATE_KEY, L1_GAS_ORACLE_SENDER_ADDR);
verifyAccount("L2_GAS_ORACLE_SENDER", L2_GAS_ORACLE_SENDER_PRIVATE_KEY, L2_GAS_ORACLE_SENDER_ADDR);
}

function verifyAccount(
string memory name,
uint256 privateKey,
address addr
) private pure {
if (vm.addr(privateKey) != addr) {
revert(
string(
abi.encodePacked(
"[ERROR] ",
name,
"_ADDR (",
vm.toString(addr),
") does not match ",
name,
"_PRIVATE_KEY"
)
)
);
}
}
}
50 changes: 50 additions & 0 deletions scripts/deterministic/Constants.sol

Large diffs are not rendered by default.

Loading
Loading