Skip to content

Commit

Permalink
gateway ctm logic closer to actual upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavBreadless committed Oct 23, 2024
1 parent 5979586 commit db9b886
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 11 deletions.
4 changes: 2 additions & 2 deletions etc/env/file_based/genesis.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
genesis_root: 0x1d286d7d9623d14d5ac17d55c6797562747ba638a372cf0470d92836ef2fc140
genesis_root: 0x708cda247cb5cd1a72c4253835d3ce23f7fd7168d100f592e505c74f327c86ba
genesis_rollup_leaf_index: 70
genesis_batch_commitment: 0x55b2c1e8c336f2db42204d64f6133e55d98cd8175ba35a393646a21e1e80346b
genesis_batch_commitment: 0x89724ef6223a396255a18b60b2114cf06925189fcc1c107e91b4f24e479a6de2
genesis_protocol_version: 25
default_aa_hash: 0x0100055d4fddeeba9063fbdecd1dde707c04f84fdbd1b576f5230977e78ca775
bootloader_hash: 0x010008c79fe70427642db69b14314af076e5d54f1dada975b905bcbb5feb9f9e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ pub struct GatewayEcosystemUpgradeContractsOutput {
pub diamond_init_max_pubdata_per_batch: u64,
pub diamond_init_minimal_l2_gas_price: u64,
pub diamond_init_priority_tx_max_pubdata: u64,
// FIXME delete it
pub expected_l2_gateway_upgrade: Address,
pub expected_rollup_l2_da_validator: Address,
pub expected_validium_l2_da_validator: Address,

Expand All @@ -58,7 +56,6 @@ pub struct GatewayEcosystemUpgradeContractsOutput {
pub struct GatewayEcosystemUpgradeDeployedAddresses {
// TODO: also deploy new chainadmin / access control restriction for the ecosystem
pub native_token_vault_addr: Address,
pub permanent_rollup_restriction: Address,
pub rollup_l1_da_validator_addr: Address,
pub validator_timelock_addr: Address,
pub validium_l1_da_validator_addr: Address,
Expand Down
39 changes: 39 additions & 0 deletions zk_toolbox/crates/zk_inception/src/accept_ownership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ lazy_static! {
"function governanceAcceptOwner(address governor, address target) public",
"function chainAdminAcceptAdmin(address admin, address target) public",
"function setDAValidatorPair(address chainAdmin, address target, address l1DaValidator, address l2DaValidator) public",
"function makePermanentRollup(address chainAdmin, address target) public",
"function governanceExecuteCalls(bytes calldata callsToExecute, address target) public",
"function adminExecuteUpgrade(bytes memory diamondCut, address adminAddr, address accessControlRestriction, address chainDiamondProxy)",
"function adminScheduleUpgrade(address adminAddr, address accessControlRestriction, uint256 newProtocolVersion, uint256 timestamp)",
Expand Down Expand Up @@ -137,6 +138,44 @@ pub async fn set_da_validator_pair(
accept_ownership(shell, governor, forge).await
}


#[allow(clippy::too_many_arguments)]
pub async fn make_permanent_rollup(
shell: &Shell,
ecosystem_config: &EcosystemConfig,
chain_admin_addr: Address,
governor: Option<H256>,
diamond_proxy_address: Address,
forge_args: &ForgeScriptArgs,
l1_rpc_url: String,
) -> anyhow::Result<()> {
// resume doesn't properly work here.
let mut forge_args = forge_args.clone();
forge_args.resume = false;

let calldata = ACCEPT_ADMIN
.encode(
"makePermanentRollup",
(
chain_admin_addr,
diamond_proxy_address,
),
)
.unwrap();
let foundry_contracts_path = ecosystem_config.path_to_l1_foundry();
let forge = Forge::new(&foundry_contracts_path)
.script(
&ACCEPT_GOVERNANCE_SCRIPT_PARAMS.script(),
forge_args.clone(),
)
.with_ffi()
.with_rpc_url(l1_rpc_url)
.with_broadcast()
.with_calldata(&calldata);
accept_ownership(shell, governor, forge).await
}


#[allow(clippy::too_many_arguments)]
pub async fn governance_execute_calls(
shell: &Shell,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,17 @@ lazy_static! {
])
.unwrap(),
);

static ref DEPLOY_GATEWAY_CTM_INTERFACE: BaseContract = BaseContract::from(
parse_abi(&[
"function prepareAddresses() public",
"function deployCTM() public",
])
.unwrap(),
);
}


pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> {
let chain_name = global_config().chain_name.clone();
let ecosystem_config = EcosystemConfig::from_file(shell)?;
Expand All @@ -54,7 +63,7 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> {
let chain_genesis_config = chain_config.get_genesis_config()?;

// Firstly, deploying gateway contracts
let gateway_config = deploy_gateway_ctm(
let gateway_config = calculate_gateway_ctm(
shell,
args.clone(),
&ecosystem_config,
Expand Down Expand Up @@ -86,25 +95,39 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> {

let output = call_script(
shell,
args,
args.clone(),
&GATEWAY_PREPARATION_INTERFACE
.encode("deployAndSetGatewayTransactionFilterer", ())
.unwrap(),
&ecosystem_config,
&chain_config,
chain_config.get_wallets_config()?.governor_private_key(),
l1_url,
l1_url.clone(),
)
.await?;

chain_contracts_config.set_transaction_filterer(output.gateway_transaction_filterer_proxy);

// We could've deployed the CTM at the beginnig however, to be closer to how the actual upgrade
// looks like we'll do it as the last step

deploy_gateway_ctm(
shell,
args,
&ecosystem_config,
&chain_config,
&chain_genesis_config,
&ecosystem_config.get_initial_deployment_config().unwrap(),
l1_url,
)
.await?;

chain_contracts_config.save_with_base_path(shell, chain_config.configs)?;

Ok(())
}

async fn deploy_gateway_ctm(
async fn calculate_gateway_ctm(
shell: &Shell,
forge_args: ForgeScriptArgs,
config: &EcosystemConfig,
Expand All @@ -125,10 +148,15 @@ async fn deploy_gateway_ctm(
);
deploy_config.save(shell, deploy_config_path)?;

let calldata = DEPLOY_GATEWAY_CTM_INTERFACE
.encode("deployCTM", ())
.unwrap();

let mut forge = Forge::new(&config.path_to_l1_foundry())
.script(&DEPLOY_GATEWAY_CTM.script(), forge_args.clone())
.with_ffi()
.with_rpc_url(l1_rpc_url)
.with_calldata(&calldata)
.with_broadcast();

// Governor private key should not be needed for this script
Expand All @@ -146,6 +174,46 @@ async fn deploy_gateway_ctm(
Ok(gateway_config)
}

async fn deploy_gateway_ctm(
shell: &Shell,
forge_args: ForgeScriptArgs,
config: &EcosystemConfig,
chain_config: &ChainConfig,
chain_genesis_config: &GenesisConfig,
initial_deployemnt_config: &InitialDeploymentConfig,
l1_rpc_url: String,
) -> anyhow::Result<()> {
let contracts_config = chain_config.get_contracts_config()?;
let deploy_config_path = DEPLOY_GATEWAY_CTM.input(&config.link_to_code);

let deploy_config = DeployGatewayCTMInput::new(
chain_config,
config,
chain_genesis_config,
&contracts_config,
initial_deployemnt_config,
);
deploy_config.save(shell, deploy_config_path)?;

let calldata = DEPLOY_GATEWAY_CTM_INTERFACE
.encode("prepareAddresses", ())
.unwrap();

let mut forge = Forge::new(&config.path_to_l1_foundry())
.script(&DEPLOY_GATEWAY_CTM.script(), forge_args.clone())
.with_ffi()
.with_rpc_url(l1_rpc_url)
.with_calldata(&calldata)
.with_broadcast();

// Governor private key should not be needed for this script
forge = fill_forge_private_key(forge, config.get_wallets()?.deployer_private_key())?;
check_the_balance(&forge).await?;
forge.run(shell)?;

Ok(())
}

async fn gateway_governance_whitelisting(
shell: &Shell,
forge_args: ForgeScriptArgs,
Expand Down
17 changes: 16 additions & 1 deletion zk_toolbox/crates/zk_inception/src/commands/chain/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use types::{BaseToken, L1BatchCommitmentMode};
use xshell::Shell;

use crate::{
accept_ownership::{accept_admin, set_da_validator_pair},
accept_ownership::{accept_admin, make_permanent_rollup, set_da_validator_pair},
commands::chain::{
args::init::{
configs::{InitConfigsArgs, InitConfigsArgsFinal},
Expand Down Expand Up @@ -181,6 +181,21 @@ pub async fn init(
.await?;
spinner.finish();

if !validium_mode {
println!("Making permanent rollup!");
make_permanent_rollup(
shell,
ecosystem_config,
contracts_config.l1.chain_admin_addr,
chain_config.get_wallets_config()?.governor_private_key(),
contracts_config.l1.diamond_proxy_addr,
&init_args.forge_args.clone(),
init_args.l1_rpc_url.clone(),
)
.await?;
println!("Done");
}

// Setup legacy bridge - shouldn't be used for new chains (run by L1 Governor)
if let Some(true) = chain_config.legacy_bridge {
setup_legacy_bridge(
Expand Down

0 comments on commit db9b886

Please sign in to comment.