Skip to content

Commit

Permalink
Merge branch 'feat-deployment-alt-gas-token' of https://github.com/sc…
Browse files Browse the repository at this point in the history
…roll-tech/scroll-contracts into feat-deployment-alt-gas-token
  • Loading branch information
yiweichi committed Aug 7, 2024
2 parents fbd92da + 3082fc1 commit 85cd399
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 7 deletions.
1 change: 1 addition & 0 deletions docker/Dockerfile.gen-configs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ COPY ./docker/templates/config-contracts.toml /contracts/docker/templates/config
COPY ./docker/templates/coordinator-config.json /contracts/docker/templates/coordinator-config.json
COPY ./docker/templates/genesis.json /contracts/docker/templates/genesis.json
COPY ./docker/templates/rollup-config.json /contracts/docker/templates/rollup-config.json
COPY ./docker/templates/rollup-explorer-backend-config.json /contracts/docker/templates/rollup-explorer-backend-config.json

COPY ./docker/scripts/gen-configs.sh /contracts/docker/scripts/gen-configs.sh

Expand Down
4 changes: 3 additions & 1 deletion docker/config-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ CHAIN_ID_L2 = 222222

MAX_TX_IN_CHUNK = 100
MAX_BLOCK_IN_CHUNK = 100
MAX_L1_MESSAGE_GAS_LIMIT = 10000
MAX_CHUNK_IN_BATCH = 15
MAX_L1_MESSAGE_GAS_LIMIT = 10000000

L1_CONTRACT_DEPLOYMENT_BLOCK = 0

Expand Down Expand Up @@ -45,6 +46,7 @@ L2GETH_SIGNER_0_ADDRESS = "0x756EA06BDEe36de11F22DCca45a31d8a178eF3c6"
SCROLL_DB_CONNECTION_STRING = "postgres://postgres:scroll2022@db:5432/scroll?sslmode=disable"
CHAIN_MONITOR_DB_CONNECTION_STRING = "postgres://postgres:scroll2022@db:5432/chain_monitor?sslmode=disable"
BRIDGE_HISTORY_DB_CONNECTION_STRING = "postgres://postgres:scroll2022@db:5432/bridge_history?sslmode=disable"
ROLLUP_EXPLORER_DB_CONNECTION_STRING = "postgres://postgres:scroll2022@db:5432/rollup_explorer?sslmode=disable"


[genesis]
Expand Down
11 changes: 11 additions & 0 deletions docker/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ forge script scripts/deterministic/DeployScroll.s.sol:DeployScroll --rpc-url "$L
echo ""
echo "deploying on L2"
forge script scripts/deterministic/DeployScroll.s.sol:DeployScroll --rpc-url "$L2_RPC_ENDPOINT" --batch-size "$BATCH_SIZE" --sig "run(string,string)" "L2" "verify-config" --broadcast --legacy || exit 1

# log broadcast files
echo ""
echo "Broadcast files:"
for file in broadcast/DeployScroll.s.sol/*/*; do
if [ -f "$file" ]; then
echo "$file:"
cat "$file"
echo ""
fi
done
4 changes: 4 additions & 0 deletions docker/scripts/gen-configs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ forge script scripts/deterministic/GenerateConfigs.s.sol:GenerateBalanceCheckerC
echo ""
echo "generating .env.frontend"
forge script scripts/deterministic/GenerateConfigs.s.sol:GenerateFrontendConfig || exit 1

echo ""
echo "generating rollup-explorer-backend-config.json"
forge script scripts/deterministic/GenerateConfigs.s.sol:GenerateRollupExplorerBackendConfig || exit 1
2 changes: 1 addition & 1 deletion docker/templates/bridge-history-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"L1": {
"confirmation": 0,
"endpoint": null,
"startHeight": 0,
"startHeight": null,
"blockTime": 12,
"fetchLimit": 16,
"MessageQueueAddr": null,
Expand Down
6 changes: 3 additions & 3 deletions docker/templates/rollup-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
"gas_price_diff": 50000
},
"chain_monitor": {
"enabled": true,
"enabled": false,
"timeout": 3,
"try_times": 5,
"base_url": "http://chain-monitorv2:8080"
"base_url": "http://chain-monitor:8080"
},
"enable_test_env_bypass_features": null,
"finalize_batch_without_proof_timeout_sec": null,
Expand All @@ -72,7 +72,7 @@
"max_uncompressed_batch_bytes_size": 634880
},
"batch_proposer_config": {
"max_chunk_num_per_batch": 15,
"max_chunk_num_per_batch": null,
"max_l1_commit_gas_per_batch": 5000000,
"max_l1_commit_calldata_size_per_batch": 110000,
"batch_timeout_sec": 2700,
Expand Down
5 changes: 5 additions & 0 deletions docker/templates/rollup-explorer-backend-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"db_url": null,
"open_api_addr": "/rollupscan",
"max_per_page": 500
}
86 changes: 86 additions & 0 deletions docs/manual-deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Manual Deployment @scroll-tech/scroll-contracts

## Overview

This document will guide you through manually deploying Scroll contracts to both layer 1 and layer 2 networks.

### Requirements

This repository requires `node` version>=20.12.2, `yarn` and `foundry` to be previously installed.

- **Node.js:** https://nodejs.org/en/download/package-manager
- **Yarn:** https://www.npmjs.com/package/yarn
- **Foundry:** https://book.getfoundry.sh/getting-started/installation

### Config

1. Create directory `volume` on the root directory of the repo (all config file will be put or generated under this directory)

```bash
mkdir volume
```

2. Create config file, and copy config variables from example file `./docker/config-example.toml`

```bash
cp ./docker/config-example.toml ./volume/config.toml
```

If you've previously launched Scroll chain cocomponents using Scroll-SDK, you may already have a config.toml file. If so directly copy it to `./volume/config.toml`.
**Important Note: If you are launching a scroll chain through scroll-sdk, make sure this config.toml file stay same as the one used in scroll-sdk.**

Details about the some important variables you may want to change:

| Configuration Variable | Description |
| -------------------------------- | ---------------------------------------------------------------------------------------- |
| L1_RPC_ENDPOINT | The RPC endpoint for the layer 1 network |
| L2_RPC_ENDPOINT | The RPC endpoint for the layer 2 network |
| CHAIN_ID_L1 | The chain ID of the layer 1 network |
| CHAIN_ID_L2 | The chain ID of the layer 2 network |
| DEPLOYER_PRIVATE_KEY | The private key of the deployer on both layer 1 and layer 2 |
| OWNER_PRIVATE_KEY | The private key of the owner of Scroll contracts on both layer 1 and layer 2 |
| L1_COMMIT_SENDER_PRIVATE_KEY | The private key of the commit sender (sequencer) on layer 1 |
| L1_FINALIZE_SENDER_PRIVATE_KEY | The private key of the finalize sender (prover) on layer 1 |
| L1_GAS_ORACLE_SENDER_PRIVATE_KEY | The private key of the gas oracle sender on layer 1 |
| L2_GAS_ORACLE_SENDER_PRIVATE_KEY | The private key of the gas oracle sender on layer 2 |
| DEPLOYER_ADDR | The address of the deployer on both layer 1 and layer 2 |
| OWNER_ADDR | The address of the owner of Scroll contracts on both layer 1 and layer 2 |
| L1_COMMIT_SENDER_ADDR | The address of the commit sender (sequencer) on layer 1 |
| L1_FINALIZE_SENDER_ADDR | The address of the finalize sender (prover) on layer 1 |
| L1_GAS_ORACLE_SENDER_ADDR | The address of the gas oracle sender on layer 1 |
| L2_GAS_ORACLE_SENDER_ADDR | The address of the gas oracle sender on layer 2 |
| DEPLOYMENT_SALT | The salt used to deploy contracts, make it unique to prevent contract address collisions |
| L1_CONTRACT_DEPLOYMENT_BLOCK | The block that l2-sequencer and bridge-history-fetcher start to sync contracts event |

### Deploy

1. Install packages

```bash
yarn install
```

2. Initialize git submodules.

```bash
git submodule update --init --recursive
```

3. Set and export environment variables (Change the RPCs to the one you are using)

```bash
export L1_RPC_ENDPOINT=http://l1-devnet.scrollsdk
export L2_RPC_ENDPOINT=http://l2-rpc.scrollsdk
```

4. Generate predicted contract addresses (This step required mainly because we are checking if every contracts deployed as we expected)

```bash
forge script scripts/deterministic/DeployScroll.s.sol:DeployScroll --sig "run(string,string)" "none" "write-config"
```

5. Deploy contracts on both layer1 and layer2 (Deployment may be interrupted by errors. Rerun the command to resume in such cases.)

```bash
./docker/scripts/deploy.sh
```
4 changes: 4 additions & 0 deletions scripts/deterministic/Configuration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ abstract contract Configuration is Script {

uint256 internal MAX_TX_IN_CHUNK;
uint256 internal MAX_BLOCK_IN_CHUNK;
uint256 internal MAX_CHUNK_IN_BATCH;
uint256 internal MAX_L1_MESSAGE_GAS_LIMIT;

uint256 internal L1_CONTRACT_DEPLOYMENT_BLOCK;
Expand Down Expand Up @@ -61,6 +62,7 @@ abstract contract Configuration is Script {
string internal SCROLL_DB_CONNECTION_STRING;
string internal CHAIN_MONITOR_DB_CONNECTION_STRING;
string internal BRIDGE_HISTORY_DB_CONNECTION_STRING;
string internal ROLLUP_EXPLORER_BACKEND_DB_CONNECTION_STRING;

// genesis
uint256 internal L2_MAX_ETH_SUPPLY;
Expand Down Expand Up @@ -105,6 +107,7 @@ abstract contract Configuration is Script {

MAX_TX_IN_CHUNK = cfg.readUint(".general.MAX_TX_IN_CHUNK");
MAX_BLOCK_IN_CHUNK = cfg.readUint(".general.MAX_BLOCK_IN_CHUNK");
MAX_CHUNK_IN_BATCH = cfg.readUint(".general.MAX_CHUNK_IN_BATCH");
MAX_L1_MESSAGE_GAS_LIMIT = cfg.readUint(".general.MAX_L1_MESSAGE_GAS_LIMIT");

L1_CONTRACT_DEPLOYMENT_BLOCK = cfg.readUint(".general.L1_CONTRACT_DEPLOYMENT_BLOCK");
Expand Down Expand Up @@ -133,6 +136,7 @@ abstract contract Configuration is Script {
SCROLL_DB_CONNECTION_STRING = cfg.readString(".db.SCROLL_DB_CONNECTION_STRING");
CHAIN_MONITOR_DB_CONNECTION_STRING = cfg.readString(".db.CHAIN_MONITOR_DB_CONNECTION_STRING");
BRIDGE_HISTORY_DB_CONNECTION_STRING = cfg.readString(".db.BRIDGE_HISTORY_DB_CONNECTION_STRING");
ROLLUP_EXPLORER_BACKEND_DB_CONNECTION_STRING = cfg.readString(".db.ROLLUP_EXPLORER_DB_CONNECTION_STRING");

L2_MAX_ETH_SUPPLY = cfg.readUint(".genesis.L2_MAX_ETH_SUPPLY");
L2_DEPLOYER_INITIAL_BALANCE = cfg.readUint(".genesis.L2_DEPLOYER_INITIAL_BALANCE");
Expand Down
2 changes: 2 additions & 0 deletions scripts/deterministic/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ string constant COORDINATOR_CONFIG_TEMPLATE_PATH = "./docker/templates/coordinat
string constant CHAIN_MONITOR_CONFIG_TEMPLATE_PATH = "./docker/templates/chain-monitor-config.json";
string constant BRIDGE_HISTORY_CONFIG_TEMPLATE_PATH = "./docker/templates/bridge-history-config.json";
string constant BALANCE_CHECKER_CONFIG_TEMPLATE_PATH = "./docker/templates/balance-checker-config.json";
string constant ROLLUP_EXPLORER_BACKEND_CONFIG_TEMPLATE_PATH = "./docker/templates/rollup-explorer-backend-config.json";

// input files
string constant CONFIG_PATH = "./volume/config.toml";
Expand All @@ -33,3 +34,4 @@ string constant CHAIN_MONITOR_CONFIG_PATH = "./volume/chain-monitor-config.json"
string constant BRIDGE_HISTORY_CONFIG_PATH = "./volume/bridge-history-config.json";
string constant BALANCE_CHECKER_CONFIG_PATH = "./volume/balance-checker-config.json";
string constant FRONTEND_ENV_PATH = "./volume/.env.frontend";
string constant ROLLUP_EXPLORER_BACKEND_CONFIG_PATH = "./volume/rollup-explorer-backend-config.json";
2 changes: 1 addition & 1 deletion scripts/deterministic/DeterministicDeployment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ abstract contract DeterminsticDeployment is Configuration {

function setScriptMode(string memory scriptMode) internal {
if (keccak256(bytes(scriptMode)) == keccak256(bytes("log-addresses"))) {
mode = ScriptMode.WriteConfig;
mode = ScriptMode.LogAddresses;
} else if (keccak256(bytes(scriptMode)) == keccak256(bytes("write-config"))) {
mode = ScriptMode.WriteConfig;
} else if (keccak256(bytes(scriptMode)) == keccak256(bytes("verify-config"))) {
Expand Down
34 changes: 33 additions & 1 deletion scripts/deterministic/GenerateConfigs.s.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.24;

import {BALANCE_CHECKER_CONFIG_PATH, BALANCE_CHECKER_CONFIG_TEMPLATE_PATH, BRIDGE_HISTORY_CONFIG_PATH, BRIDGE_HISTORY_CONFIG_TEMPLATE_PATH, CHAIN_MONITOR_CONFIG_PATH, CHAIN_MONITOR_CONFIG_TEMPLATE_PATH, COORDINATOR_CONFIG_PATH, COORDINATOR_CONFIG_TEMPLATE_PATH, FRONTEND_ENV_PATH, ROLLUP_CONFIG_PATH, ROLLUP_CONFIG_TEMPLATE_PATH} from "./Constants.sol";
import {BALANCE_CHECKER_CONFIG_PATH, BALANCE_CHECKER_CONFIG_TEMPLATE_PATH, BRIDGE_HISTORY_CONFIG_PATH, BRIDGE_HISTORY_CONFIG_TEMPLATE_PATH, CHAIN_MONITOR_CONFIG_PATH, CHAIN_MONITOR_CONFIG_TEMPLATE_PATH, COORDINATOR_CONFIG_PATH, COORDINATOR_CONFIG_TEMPLATE_PATH, FRONTEND_ENV_PATH, ROLLUP_CONFIG_PATH, ROLLUP_CONFIG_TEMPLATE_PATH, ROLLUP_EXPLORER_BACKEND_CONFIG_PATH, ROLLUP_EXPLORER_BACKEND_CONFIG_TEMPLATE_PATH} from "./Constants.sol";
import {DeployScroll} from "./DeployScroll.s.sol";

contract GenerateRollupConfig is DeployScroll {
Expand Down Expand Up @@ -56,6 +56,7 @@ contract GenerateRollupConfig is DeployScroll {

vm.writeJson(vm.toString(MAX_BLOCK_IN_CHUNK), ROLLUP_CONFIG_PATH, ".l2_config.chunk_proposer_config.max_block_num_per_chunk");
vm.writeJson(vm.toString(MAX_TX_IN_CHUNK), ROLLUP_CONFIG_PATH, ".l2_config.chunk_proposer_config.max_tx_num_per_chunk");
vm.writeJson(vm.toString(MAX_CHUNK_IN_BATCH), ROLLUP_CONFIG_PATH, ".l2_config.batch_proposer_config.max_chunk_num_per_batch");

vm.writeJson(SCROLL_DB_CONNECTION_STRING, ROLLUP_CONFIG_PATH, ".db_config.dsn");
}
Expand Down Expand Up @@ -203,6 +204,7 @@ contract GenerateBridgeHistoryConfig is DeployScroll {

// others
vm.writeJson(BRIDGE_HISTORY_DB_CONNECTION_STRING, BRIDGE_HISTORY_CONFIG_PATH, ".db.dsn");
vm.writeJson(vm.toString(L1_CONTRACT_DEPLOYMENT_BLOCK), BRIDGE_HISTORY_CONFIG_PATH, ".L1.startHeight");
}
}

Expand Down Expand Up @@ -326,3 +328,33 @@ contract GenerateFrontendConfig is DeployScroll {
vm.writeLine(FRONTEND_ENV_PATH, "REACT_APP_L1_BATCH_BRIDGE_GATEWAY_PROXY_ADDR = \"\"");
}
}

contract GenerateRollupExplorerBackendConfig is DeployScroll {
/***************
* Entry point *
***************/

function run() public {
setScriptMode(ScriptMode.VerifyConfig);
predictAllContracts();

generateRollupExplorerBackendConfig();
}

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

// prettier-ignore
function generateRollupExplorerBackendConfig() private {
// initialize template file
if (vm.exists(ROLLUP_EXPLORER_BACKEND_CONFIG_PATH)) {
vm.removeFile(ROLLUP_EXPLORER_BACKEND_CONFIG_PATH);
}

string memory template = vm.readFile(ROLLUP_EXPLORER_BACKEND_CONFIG_TEMPLATE_PATH);
vm.writeFile(ROLLUP_EXPLORER_BACKEND_CONFIG_PATH, template);

vm.writeJson(ROLLUP_EXPLORER_BACKEND_DB_CONNECTION_STRING, ROLLUP_EXPLORER_BACKEND_CONFIG_PATH, ".db_url");
}
}

0 comments on commit 85cd399

Please sign in to comment.