Skip to content
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

feat: improve foundry l1 config deployment #378

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .github/workflows/l1-contracts-foundry-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ env:

on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -73,6 +74,10 @@ jobs:
- name: Use Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Copy configs from template
working-directory: ./l1-contracts-foundry
run: cp -r script-config-template script-config

- name: Run anvil
run: |
anvil --silent &
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ l1-contracts/report/*
l1-contracts/coverage/*
l1-contracts/out/*
l1-contracts-foundry/broadcast/*
l1-contracts-foundry/script-config/*
l1-contracts-foundry/script-out/*
!l1-contracts-foundry/script-out/.gitkeep
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
create2_factory_addr = "0x4e59b44847b379578588920cA78FbF26c0B4956C"
create2_factory_salt = "0x00000000000000000000000000000000000000000000000000000000000000ff"

[tokens.dai]
[tokens.DAI]
name = "DAI"
symbol = "DAI"
decimals = 18
implementation = "TestnetERC20Token.sol"
mint = "10000000000"

[tokens.weth]
[tokens.WETH]
name = "Wrapped Ether"
symbol = "WETH"
decimals = 18
Expand Down
19 changes: 11 additions & 8 deletions l1-contracts-foundry/script/DeployErc20.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,24 @@ contract DeployErc20Script is Script {
}

function initializeConfig() internal {
// Grab config from output of l1 deployment
config.deployerAddress = msg.sender;

string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-config/config-deploy-erc20.toml");
string memory toml = vm.readFile(path);

config.deployerAddress = msg.sender;
// Grab config from output of l1 deployment
string memory path = string.concat(root, "/script-out/output-deploy-l1.toml");
string memory toml = vm.readFile(path);

// Config file must be parsed key by key, otherwise values returned
// are parsed alfabetically and not by key.
// https://book.getfoundry.sh/cheatcodes/parse-toml
config.create2FactoryAddr = vm.parseTomlAddress(toml, "$.create2_factory_addr");
config.create2FactorySalt = vm.parseTomlBytes32(toml, "$.create2_factory_salt");

// Grab config from custom config file
path = string.concat(root, "/script-config/config-deploy-erc20.toml");
toml = vm.readFile(path);

string[] memory tokens = vm.parseTomlKeys(toml, "$.tokens");

for (uint256 i = 0; i < tokens.length; i++) {
Expand All @@ -67,7 +73,7 @@ contract DeployErc20Script is Script {

function deployTokens() internal {
for (uint256 i = 0; i < config.tokens.length; i++) {
TokenDescription memory token = config.tokens[i];
TokenDescription storage token = config.tokens[i];
console.log("Deploying token:", token.name);
address tokenAddress = deployErc20({
name: token.name,
Expand Down Expand Up @@ -110,9 +116,6 @@ contract DeployErc20Script is Script {
}

function saveOutput() internal {
vm.serializeAddress("root", "create2_factory_addr", config.create2FactoryAddr);
vm.serializeBytes32("root", "create2_factory_salt", config.create2FactorySalt);

string memory tokens = "";
for (uint256 i = 0; i < config.tokens.length; i++) {
TokenDescription memory token = config.tokens[i];
Expand Down
116 changes: 62 additions & 54 deletions l1-contracts-foundry/script/DeployL1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -563,116 +563,124 @@ contract DeployL1Script is Script {
}

function saveOutput() internal {
vm.serializeAddress("l1.bridgehub", "bridgehub_proxy_addr", addresses.bridgehub.bridgehubProxy);
string memory l1Bridgehub = vm.serializeAddress(
"l1.bridgehub",
vm.serializeAddress("bridgehub", "bridgehub_proxy_addr", addresses.bridgehub.bridgehubProxy);
string memory bridgehub = vm.serializeAddress(
"bridgehub",
"bridgehub_implementation_addr",
addresses.bridgehub.bridgehubImplementation
);

vm.serializeAddress(
"l1.state_transition",
"state_transition",
"state_transition_proxy_addr",
addresses.stateTransition.stateTransitionProxy
);
vm.serializeAddress(
"l1.state_transition",
"state_transition",
"state_transition_implementation_addr",
addresses.stateTransition.stateTransitionImplementation
);
vm.serializeAddress("l1.state_transition", "verifier_addr", addresses.stateTransition.verifier);
vm.serializeAddress("l1.state_transition", "admin_facet_addr", addresses.stateTransition.adminFacet);
vm.serializeAddress("l1.state_transition", "mailbox_facet_addr", addresses.stateTransition.mailboxFacet);
vm.serializeAddress("l1.state_transition", "executor_facet_addr", addresses.stateTransition.executorFacet);
vm.serializeAddress("l1.state_transition", "getters_facet_addr", addresses.stateTransition.gettersFacet);
vm.serializeAddress("l1.state_transition", "diamond_init_addr", addresses.stateTransition.diamondInit);
vm.serializeAddress("l1.state_transition", "genesis_upgrade_addr", addresses.stateTransition.genesisUpgrade);
vm.serializeAddress("l1.state_transition", "default_upgrade_addr", addresses.stateTransition.defaultUpgrade);
string memory l1StateTransition = vm.serializeAddress(
"l1.state_transition",
vm.serializeAddress("state_transition", "verifier_addr", addresses.stateTransition.verifier);
vm.serializeAddress("state_transition", "admin_facet_addr", addresses.stateTransition.adminFacet);
vm.serializeAddress("state_transition", "mailbox_facet_addr", addresses.stateTransition.mailboxFacet);
vm.serializeAddress("state_transition", "executor_facet_addr", addresses.stateTransition.executorFacet);
vm.serializeAddress("state_transition", "getters_facet_addr", addresses.stateTransition.gettersFacet);
vm.serializeAddress("state_transition", "diamond_init_addr", addresses.stateTransition.diamondInit);
vm.serializeAddress("state_transition", "genesis_upgrade_addr", addresses.stateTransition.genesisUpgrade);
vm.serializeAddress("state_transition", "default_upgrade_addr", addresses.stateTransition.defaultUpgrade);
string memory stateTransition = vm.serializeAddress(
"state_transition",
"diamond_proxy_addr",
addresses.stateTransition.diamondProxy
);

vm.serializeAddress("bridges", "erc20_bridge_implementation_addr", addresses.bridges.erc20BridgeImplementation);
vm.serializeAddress("bridges", "erc20_bridge_proxy_addr", addresses.bridges.erc20BridgeProxy);
vm.serializeAddress(
"l1.bridges",
"erc20_bridge_implementation_addr",
addresses.bridges.erc20BridgeImplementation
);
vm.serializeAddress("l1.bridges", "erc20_bridge_proxy_addr", addresses.bridges.erc20BridgeProxy);
vm.serializeAddress(
"l1.bridges",
"bridges",
"shared_bridge_implementation_addr",
addresses.bridges.sharedBridgeImplementation
);
string memory l1Bridges = vm.serializeAddress(
"l1.bridges",
string memory bridges = vm.serializeAddress(
"bridges",
"shared_bridge_proxy_addr",
addresses.bridges.sharedBridgeProxy
);

vm.serializeUint(
"l1.config",
"contracts_config",
"diamond_init_pubdata_pricing_mode",
uint256(config.contracts.diamondInitPubdataPricingMode)
);
vm.serializeUint(
"l1.config",
"contracts_config",
"diamond_init_batch_overhead_l1_gas",
config.contracts.diamondInitBatchOverheadL1Gas
);
vm.serializeUint(
"l1.config",
"contracts_config",
"diamond_init_max_pubdata_per_batch",
config.contracts.diamondInitMaxPubdataPerBatch
);
vm.serializeUint(
"l1.config",
"contracts_config",
"diamond_init_max_l2_gas_per_batch",
config.contracts.diamondInitMaxL2GasPerBatch
);
vm.serializeUint(
"l1.config",
"contracts_config",
"diamond_init_priority_tx_max_pubdata",
config.contracts.diamondInitPriorityTxMaxPubdata
);
vm.serializeUint(
"l1.config",
"contracts_config",
"diamond_init_minimal_l2_gas_price",
config.contracts.diamondInitMinimalL2GasPrice
);
vm.serializeBytes32("l1.config", "recursion_node_level_vk_hash", config.contracts.recursionNodeLevelVkHash);
vm.serializeBytes32("l1.config", "recursion_leaf_level_vk_hash", config.contracts.recursionLeafLevelVkHash);
vm.serializeBytes32(
"l1.config",
"contracts_config",
"recursion_node_level_vk_hash",
config.contracts.recursionNodeLevelVkHash
);
vm.serializeBytes32(
"contracts_config",
"recursion_leaf_level_vk_hash",
config.contracts.recursionLeafLevelVkHash
);
vm.serializeBytes32(
"contracts_config",
"recursion_circuits_set_vks_hash",
config.contracts.recursionCircuitsSetVksHash
);
string memory l1Config = vm.serializeUint(
"l1.config",
string memory contractsConfig = vm.serializeUint(
"contracts_config",
"priority_tx_max_gas_limit",
config.contracts.priorityTxMaxGasLimit
);

vm.serializeAddress("l1", "transparent_proxy_admin_addr", addresses.transparentProxyAdmin);
vm.serializeAddress("l1", "governance_addr", addresses.governance);
vm.serializeAddress("l1", "blob_versioned_hash_retriever_addr", addresses.blobVersionedHashRetriever);
vm.serializeAddress("l1", "validator_timelock_addr", addresses.validatorTimelock);
vm.serializeAddress("l1", "create2_factory_addr", addresses.create2Factory);
vm.serializeBytes32("l1", "create2_factory_salt", config.contracts.create2FactorySalt);
vm.serializeAddress("l1", "multicall3_addr", config.contracts.multicall3Addr);
vm.serializeUint("l1", "l1_chain_id", config.l1ChainId);
vm.serializeUint("l1", "era_chain_id", config.eraChainId);
vm.serializeString("l1", "bridgehub", l1Bridgehub);
vm.serializeString("l1", "state_transition", l1StateTransition);
vm.serializeString("l1", "config", l1Config);
vm.serializeAddress("l1", "deployer_addr", config.deployerAddress);
vm.serializeAddress("l1", "owner_addr", config.ownerAddress);
string memory l1 = vm.serializeString("l1", "bridges", l1Bridges);

string memory toml = vm.serializeString("toml", "l1", l1);
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-out/output-deploy-l1.toml");
vm.serializeAddress("deployed_addresses", "transparent_proxy_admin_addr", addresses.transparentProxyAdmin);
vm.serializeAddress("deployed_addresses", "governance_addr", addresses.governance);
vm.serializeAddress(
"deployed_addresses",
"blob_versioned_hash_retriever_addr",
addresses.blobVersionedHashRetriever
);
vm.serializeAddress("deployed_addresses", "validator_timelock_addr", addresses.validatorTimelock);
vm.serializeString("deployed_addresses", "bridgehub", bridgehub);
vm.serializeString("deployed_addresses", "state_transition", stateTransition);
string memory deployedAddresses = vm.serializeString("deployed_addresses", "bridges", bridges);

vm.serializeAddress("root", "create2_factory_addr", addresses.create2Factory);
vm.serializeBytes32("root", "create2_factory_salt", config.contracts.create2FactorySalt);
vm.serializeAddress("root", "multicall3_addr", config.contracts.multicall3Addr);
vm.serializeUint("root", "l1_chain_id", config.l1ChainId);
vm.serializeUint("root", "era_chain_id", config.eraChainId);
vm.serializeAddress("root", "deployer_addr", config.deployerAddress);
vm.serializeString("root", "deployed_addresses", deployedAddresses);
vm.serializeString("root", "contracts_config", contractsConfig);
string memory toml = vm.serializeAddress("root", "owner_addr", config.ownerAddress);

string memory path = string.concat(vm.projectRoot(), "/script-out/output-deploy-l1.toml");
vm.writeToml(toml, path);
}

Expand Down
8 changes: 4 additions & 4 deletions l1-contracts-foundry/script/InitializeL2WethToken.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ contract InitializeL2WethTokenScript is Script {
string memory path = string.concat(root, "/script-out/output-deploy-l1.toml");
string memory toml = vm.readFile(path);

config.create2FactoryAddr = toml.readAddress("$.l1.create2_factory_addr");
config.create2FactorySalt = toml.readBytes32("$.l1.create2_factory_salt");
config.eraChainId = toml.readUint("$.l1.era_chain_id");
config.bridgehubProxyAddr = toml.readAddress("$.l1.bridgehub.bridgehub_proxy_addr");
config.create2FactoryAddr = toml.readAddress("$.create2_factory_addr");
config.create2FactorySalt = toml.readBytes32("$.create2_factory_salt");
config.eraChainId = toml.readUint("$.era_chain_id");
config.bridgehubProxyAddr = toml.readAddress("$.deployed_addresses.bridgehub.bridgehub_proxy_addr");

// Parse some config from output of erc20 tokens deployment
path = string.concat(root, "/script-out/output-deploy-erc20.toml");
Expand Down
64 changes: 42 additions & 22 deletions l1-contracts-foundry/script/RegisterHyperchain.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ contract RegisterHyperchainScript is Script {
registerHyperchain();
addValidators();
configureZkSyncStateTransition();

saveOutput();
}

function initializeConfig() internal {
Expand All @@ -89,37 +91,47 @@ contract RegisterHyperchainScript is Script {
// Config file must be parsed key by key, otherwise values returned
// are parsed alfabetically and not by key.
// https://book.getfoundry.sh/cheatcodes/parse-toml
config.ownerAddress = toml.readAddress("$.l1.owner_addr");

config.addresses.bridgehub = toml.readAddress("$.l1.bridgehub.bridgehub_proxy_addr");
config.addresses.stateTransitionProxy = toml.readAddress("$.l1.state_transition.state_transition_proxy_addr");
config.addresses.adminFacet = toml.readAddress("$.l1.state_transition.admin_facet_addr");
config.addresses.gettersFacet = toml.readAddress("$.l1.state_transition.getters_facet_addr");
config.addresses.mailboxFacet = toml.readAddress("$.l1.state_transition.mailbox_facet_addr");
config.addresses.executorFacet = toml.readAddress("$.l1.state_transition.executor_facet_addr");
config.addresses.verifier = toml.readAddress("$.l1.state_transition.verifier_addr");
config.addresses.blobVersionedHashRetriever = toml.readAddress("$.l1.blob_versioned_hash_retriever_addr");
config.addresses.diamondInit = toml.readAddress("$.l1.state_transition.diamond_init_addr");
config.addresses.validatorTimelock = toml.readAddress("$.l1.validator_timelock_addr");
config.ownerAddress = toml.readAddress("$.owner_addr");

config.addresses.bridgehub = toml.readAddress("$.deployed_addresses.bridgehub.bridgehub_proxy_addr");
config.addresses.stateTransitionProxy = toml.readAddress(
"$.deployed_addresses.state_transition.state_transition_proxy_addr"
);
config.addresses.adminFacet = toml.readAddress("$.deployed_addresses.state_transition.admin_facet_addr");
config.addresses.gettersFacet = toml.readAddress("$.deployed_addresses.state_transition.getters_facet_addr");
config.addresses.mailboxFacet = toml.readAddress("$.deployed_addresses.state_transition.mailbox_facet_addr");
config.addresses.executorFacet = toml.readAddress("$.deployed_addresses.state_transition.executor_facet_addr");
config.addresses.verifier = toml.readAddress("$.deployed_addresses.state_transition.verifier_addr");
config.addresses.blobVersionedHashRetriever = toml.readAddress(
"$.deployed_addresses.blob_versioned_hash_retriever_addr"
);
config.addresses.diamondInit = toml.readAddress("$.deployed_addresses.state_transition.diamond_init_addr");
config.addresses.validatorTimelock = toml.readAddress("$.deployed_addresses.validator_timelock_addr");

config.contracts.diamondInitPubdataPricingMode = PubdataPricingMode(
toml.readUint("$.l1.config.diamond_init_pubdata_pricing_mode")
toml.readUint("$.contracts_config.diamond_init_pubdata_pricing_mode")
);
config.contracts.diamondInitBatchOverheadL1Gas = toml.readUint(
"$.l1.config.diamond_init_batch_overhead_l1_gas"
"$.contracts_config.diamond_init_batch_overhead_l1_gas"
);
config.contracts.diamondInitMaxPubdataPerBatch = toml.readUint(
"$.l1.config.diamond_init_max_pubdata_per_batch"
"$.contracts_config.diamond_init_max_pubdata_per_batch"
);
config.contracts.diamondInitMaxL2GasPerBatch = toml.readUint(
"$.contracts_config.diamond_init_max_l2_gas_per_batch"
);
config.contracts.diamondInitMaxL2GasPerBatch = toml.readUint("$.l1.config.diamond_init_max_l2_gas_per_batch");
config.contracts.diamondInitPriorityTxMaxPubdata = toml.readUint(
"$.l1.config.diamond_init_priority_tx_max_pubdata"
"$.contracts_config.diamond_init_priority_tx_max_pubdata"
);
config.contracts.diamondInitMinimalL2GasPrice = toml.readUint("$.l1.config.diamond_init_minimal_l2_gas_price");
config.contracts.recursionNodeLevelVkHash = toml.readBytes32("$.l1.config.recursion_node_level_vk_hash");
config.contracts.recursionLeafLevelVkHash = toml.readBytes32("$.l1.config.recursion_leaf_level_vk_hash");
config.contracts.recursionCircuitsSetVksHash = toml.readBytes32("$.l1.config.recursion_circuits_set_vks_hash");
config.contracts.priorityTxMaxGasLimit = toml.readUint("$.l1.config.priority_tx_max_gas_limit");
config.contracts.diamondInitMinimalL2GasPrice = toml.readUint(
"$.contracts_config.diamond_init_minimal_l2_gas_price"
);
config.contracts.recursionNodeLevelVkHash = toml.readBytes32("$.contracts_config.recursion_node_level_vk_hash");
config.contracts.recursionLeafLevelVkHash = toml.readBytes32("$.contracts_config.recursion_leaf_level_vk_hash");
config.contracts.recursionCircuitsSetVksHash = toml.readBytes32(
"$.contracts_config.recursion_circuits_set_vks_hash"
);
config.contracts.priorityTxMaxGasLimit = toml.readUint("$.contracts_config.priority_tx_max_gas_limit");

// Grab config from l1 deployment config
root = vm.projectRoot();
Expand Down Expand Up @@ -258,6 +270,7 @@ contract RegisterHyperchainScript is Script {
revert("Diamond proxy address not found");
}
config.addresses.newDiamondProxy = diamondProxyAddress;
console.log("Hyperchain diamond proxy deployed at:", diamondProxyAddress);
}

function addValidators() internal {
Expand Down Expand Up @@ -288,4 +301,11 @@ contract RegisterHyperchainScript is Script {
vm.stopBroadcast();
console.log("ZkSync State Transition configured");
}

function saveOutput() internal {
string memory toml = vm.serializeAddress("root", "diamond_proxy_addr", config.addresses.newDiamondProxy);
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-out/output-register-hyperchain.toml");
vm.writeToml(toml, path);
}
}
Loading