-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zk_toolbox): add
zki ecosystem build
subcommand (#2787)
## What ❔ <!-- What are the changes this PR brings about? --> <!-- Example: This PR adds a PR template to the repo. --> <!-- (For bigger PRs adding more context is appreciated) --> Add `zki ecosystem build` subcommand, which builds L1 transactions without signing and broadcasting them. This allows a security team to sign them using keys in cold storage and multisig. ```bash Create transactions to build ecosystem contracts Usage: zki ecosystem build-transactions [OPTIONS] Options: --sender <SENDER> Address of the transaction sender --l1-rpc-url <L1_RPC_URL> L1 RPC URL -o, --out <OUT> Output directory for the generated files -h, --help Print help (see a summary with '-h') ``` ```bash Create unsigned transactions for chain deployment Usage: zki chain build-transactions [OPTIONS] Options: -o, --out <OUT> Output directory for the generated files -h, --help Print help (see a summary with '-h') ``` ### Output ```json # /transactions/deploy.json { "transactions": [ { "hash": null, "transactionType": "CREATE", "contractName": null, "contractAddress": "0xddca24376aa96d8f56667d78306a3bbbdc65b1ff", "function": null, "arguments": null, "transaction": { "from": "0xaf9d732e8a5607caccb72df525851849c33edf9e", "gas": "0x15a02", "value": "0x0", "input": "0x604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3", "nonce": "0x0", "chainId": "0x9" }, "additionalContracts": [], "isFixedGasLimit": false }, { "hash": null, "transactionType": "CALL", "contractName": null, "contractAddress": "0xddca24376aa96d8f56667d78306a3bbbdc65b1ff", "function": null, "arguments": null, "transaction": { "from": "0xaf9d732e8a5607caccb72df525851849c33edf9e", "to": "0xddca24376aa96d8f56667d78306a3bbbdc65b1ff", "gas": "0xfb603", "value": "0x0", "input": ... ``` ## Why ❔ <!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? --> <!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. --> ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [x] Code has been formatted via `zk fmt` and `zk lint`.
- Loading branch information
1 parent
9d40704
commit 73c0b7c
Showing
30 changed files
with
881 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,3 +117,4 @@ chains/era/configs/* | |
configs/* | ||
era-observability/ | ||
core/tests/ts-integration/deployments-zk | ||
transactions/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
zk_toolbox/crates/zk_inception/src/commands/chain/args/build_transactions.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::path::PathBuf; | ||
|
||
use clap::Parser; | ||
use common::{config::global_config, forge::ForgeScriptArgs, Prompt}; | ||
use serde::{Deserialize, Serialize}; | ||
use url::Url; | ||
|
||
use crate::{ | ||
consts::DEFAULT_UNSIGNED_TRANSACTIONS_DIR, | ||
defaults::LOCAL_RPC_URL, | ||
messages::{MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT}, | ||
}; | ||
|
||
const CHAIN_SUBDIR: &str = "chain"; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, Parser)] | ||
pub struct BuildTransactionsArgs { | ||
/// Output directory for the generated files. | ||
#[arg(long, short)] | ||
pub out: Option<PathBuf>, | ||
/// All ethereum environment related arguments | ||
#[clap(flatten)] | ||
#[serde(flatten)] | ||
pub forge_args: ForgeScriptArgs, | ||
#[clap(long, help = MSG_L1_RPC_URL_HELP)] | ||
pub l1_rpc_url: Option<String>, | ||
} | ||
|
||
impl BuildTransactionsArgs { | ||
pub fn fill_values_with_prompt(self, default_chain: String) -> BuildTransactionsArgsFinal { | ||
let chain_name = global_config().chain_name.clone(); | ||
|
||
let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { | ||
Prompt::new(MSG_L1_RPC_URL_PROMPT) | ||
.default(LOCAL_RPC_URL) | ||
.validate_with(|val: &String| -> Result<(), String> { | ||
Url::parse(val) | ||
.map(|_| ()) | ||
.map_err(|_| MSG_L1_RPC_URL_INVALID_ERR.to_string()) | ||
}) | ||
.ask() | ||
}); | ||
|
||
BuildTransactionsArgsFinal { | ||
out: self | ||
.out | ||
.unwrap_or(PathBuf::from(DEFAULT_UNSIGNED_TRANSACTIONS_DIR).join(CHAIN_SUBDIR)) | ||
.join(chain_name.unwrap_or(default_chain)), | ||
forge_args: self.forge_args, | ||
l1_rpc_url, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone)] | ||
pub struct BuildTransactionsArgsFinal { | ||
pub out: PathBuf, | ||
pub forge_args: ForgeScriptArgs, | ||
pub l1_rpc_url: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod build_transactions; | ||
pub mod create; | ||
pub mod genesis; | ||
pub mod init; |
90 changes: 90 additions & 0 deletions
90
zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
use anyhow::Context; | ||
use common::{config::global_config, git, logger, spinner::Spinner}; | ||
use config::{ | ||
copy_configs, traits::SaveConfigWithBasePath, update_from_chain_config, EcosystemConfig, | ||
}; | ||
use ethers::utils::hex::ToHex; | ||
use xshell::Shell; | ||
|
||
use super::common::register_chain; | ||
use crate::{ | ||
commands::chain::args::build_transactions::BuildTransactionsArgs, | ||
messages::{ | ||
MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER, MSG_CHAIN_NOT_FOUND_ERR, | ||
MSG_CHAIN_TRANSACTIONS_BUILT, MSG_CHAIN_TXN_MISSING_CONTRACT_CONFIG, | ||
MSG_CHAIN_TXN_OUT_PATH_INVALID_ERR, MSG_PREPARING_CONFIG_SPINNER, MSG_SELECTED_CONFIG, | ||
MSG_WRITING_OUTPUT_FILES_SPINNER, | ||
}, | ||
}; | ||
|
||
const REGISTER_CHAIN_TXNS_FILE_SRC: &str = | ||
"contracts/l1-contracts/broadcast/RegisterHyperchain.s.sol/9/dry-run/run-latest.json"; | ||
const REGISTER_CHAIN_TXNS_FILE_DST: &str = "register-hyperchain-txns.json"; | ||
|
||
const SCRIPT_CONFIG_FILE_SRC: &str = | ||
"contracts/l1-contracts/script-config/register-hyperchain.toml"; | ||
const SCRIPT_CONFIG_FILE_DST: &str = "register-hyperchain.toml"; | ||
|
||
pub(crate) async fn run(args: BuildTransactionsArgs, shell: &Shell) -> anyhow::Result<()> { | ||
let config = EcosystemConfig::from_file(shell)?; | ||
let chain_name = global_config().chain_name.clone(); | ||
let chain_config = config | ||
.load_chain(chain_name) | ||
.context(MSG_CHAIN_NOT_FOUND_ERR)?; | ||
|
||
let args = args.fill_values_with_prompt(config.default_chain.clone()); | ||
|
||
git::submodule_update(shell, config.link_to_code.clone())?; | ||
|
||
let spinner = Spinner::new(MSG_PREPARING_CONFIG_SPINNER); | ||
copy_configs(shell, &config.link_to_code, &chain_config.configs)?; | ||
|
||
logger::note(MSG_SELECTED_CONFIG, logger::object_to_string(&chain_config)); | ||
|
||
let mut genesis_config = chain_config.get_genesis_config()?; | ||
update_from_chain_config(&mut genesis_config, &chain_config); | ||
|
||
// Copy ecosystem contracts | ||
let mut contracts_config = config | ||
.get_contracts_config() | ||
.context(MSG_CHAIN_TXN_MISSING_CONTRACT_CONFIG)?; | ||
contracts_config.l1.base_token_addr = chain_config.base_token.address; | ||
spinner.finish(); | ||
|
||
let spinner = Spinner::new(MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER); | ||
let governor: String = config.get_wallets()?.governor.address.encode_hex_upper(); | ||
|
||
register_chain( | ||
shell, | ||
args.forge_args.clone(), | ||
&config, | ||
&chain_config, | ||
&mut contracts_config, | ||
args.l1_rpc_url.clone(), | ||
Some(governor), | ||
false, | ||
) | ||
.await?; | ||
|
||
contracts_config.save_with_base_path(shell, &args.out)?; | ||
spinner.finish(); | ||
|
||
let spinner = Spinner::new(MSG_WRITING_OUTPUT_FILES_SPINNER); | ||
shell | ||
.create_dir(&args.out) | ||
.context(MSG_CHAIN_TXN_OUT_PATH_INVALID_ERR)?; | ||
|
||
shell.copy_file( | ||
config.link_to_code.join(REGISTER_CHAIN_TXNS_FILE_SRC), | ||
args.out.join(REGISTER_CHAIN_TXNS_FILE_DST), | ||
)?; | ||
|
||
shell.copy_file( | ||
config.link_to_code.join(SCRIPT_CONFIG_FILE_SRC), | ||
args.out.join(SCRIPT_CONFIG_FILE_DST), | ||
)?; | ||
spinner.finish(); | ||
|
||
logger::success(MSG_CHAIN_TRANSACTIONS_BUILT); | ||
Ok(()) | ||
} |
Oops, something went wrong.