Skip to content

Commit 1ee5eac

Browse files
Raid5594mm-zk
andauthored
feat: add flag to save calldata (#4471)
## What ❔ Adding the ability to save calldata for register-ctm calls (without execution) ## Why ❔ We want to execute it with PUH ## Is this a breaking change? - [ ] Yes - [x] No ## Operational changes Yes, it adds a flag `only_save_calldata` to the `register-ctm` command. ## 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). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [x] Code has been formatted via `zkstack dev fmt` and `zkstack dev lint`. --------- Co-authored-by: Marcin M <[email protected]>
1 parent ff1f540 commit 1ee5eac

File tree

7 files changed

+31
-11
lines changed

7 files changed

+31
-11
lines changed

zkstack_cli/crates/config/src/forge_interface/script_params.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub const DEPLOY_ECOSYSTEM_CORE_CONTRACTS_SCRIPT_PARAMS: ForgeScriptParams = For
3838

3939
pub const REGISTER_CTM_SCRIPT_PARAMS: ForgeScriptParams = ForgeScriptParams {
4040
input: "script-config/config-deploy-l1.toml",
41-
output: "script-out/output-deploy-l1.toml",
41+
output: "script-out/register-ctm-l1.toml",
4242
script_path: "deploy-scripts/RegisterCTM.s.sol",
4343
};
4444

zkstack_cli/crates/zkstack/src/admin_functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ impl AdminScriptMode {
407407
}
408408

409409
#[derive(Debug, Deserialize, Serialize, Clone)]
410-
struct AdminScriptOutputInner {
410+
pub(crate) struct AdminScriptOutputInner {
411411
admin_address: Address,
412412
encoded_data: String,
413413
}

zkstack_cli/crates/zkstack/src/commands/ecosystem/args/init.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ pub struct RegisterCTMArgs {
269269
pub update_submodules: Option<bool>,
270270
#[clap(long, help = MSG_DEV_ARG_HELP)]
271271
pub dev: bool,
272+
#[clap(long, default_missing_value = "false", num_args = 0..=1)]
273+
pub only_save_calldata: bool,
272274
}
273275

274276
impl RegisterCTMArgs {
@@ -281,6 +283,7 @@ impl RegisterCTMArgs {
281283
forge_args,
282284
update_submodules,
283285
dev,
286+
only_save_calldata,
284287
} = self;
285288

286289
let ecosystem = ecosystem.fill_values_with_prompt(l1_network, dev).await?;
@@ -289,6 +292,7 @@ impl RegisterCTMArgs {
289292
ecosystem,
290293
forge_args,
291294
update_submodules,
295+
only_save_calldata,
292296
})
293297
}
294298
}
@@ -298,6 +302,7 @@ pub struct RegisterCTMArgsFinal {
298302
pub ecosystem: EcosystemArgsFinal,
299303
pub forge_args: ForgeScriptArgs,
300304
pub update_submodules: Option<bool>,
305+
pub only_save_calldata: bool,
301306
}
302307

303308
impl From<EcosystemInitArgsFinal> for RegisterCTMArgsFinal {
@@ -306,6 +311,7 @@ impl From<EcosystemInitArgsFinal> for RegisterCTMArgsFinal {
306311
ecosystem: args.ecosystem,
307312
forge_args: args.forge_args,
308313
update_submodules: None,
314+
only_save_calldata: false,
309315
}
310316
}
311317
}

zkstack_cli/crates/zkstack/src/commands/ecosystem/common.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use zkstack_cli_types::{L1Network, ProverMode};
2929

3030
use super::args::init::EcosystemInitArgsFinal;
3131
use crate::{
32+
admin_functions::{AdminScriptOutput, AdminScriptOutputInner},
3233
commands::chain::{self},
3334
messages::{msg_chain_load_err, msg_initializing_chain, MSG_DEPLOYING_ERC20_SPINNER},
3435
utils::forge::{check_the_balance, fill_forge_private_key, WalletOwner},
@@ -38,6 +39,8 @@ lazy_static! {
3839
static ref DEPLOY_L1_FUNCTIONS: BaseContract = BaseContract::from(
3940
parse_abi(&["function runWithBridgehub(address bridgehub) public",]).unwrap(),
4041
);
42+
static ref REGISTER_CTM_FUNCTIONS: BaseContract =
43+
BaseContract::from(parse_abi(&["function registerCTM(bool shouldSend) public",]).unwrap(),);
4144
}
4245

4346
#[allow(clippy::too_many_arguments)]
@@ -193,13 +196,18 @@ pub async fn register_ctm_on_existing_bh(
193196
config: &EcosystemConfig,
194197
l1_rpc_url: &str,
195198
sender: Option<String>,
196-
broadcast: bool,
197-
) -> anyhow::Result<()> {
199+
only_save_calldata: bool,
200+
) -> anyhow::Result<AdminScriptOutput> {
198201
let wallets_config = config.get_wallets()?;
199202

203+
let calldata = REGISTER_CTM_FUNCTIONS
204+
.encode("registerCTM", !only_save_calldata)
205+
.unwrap();
206+
200207
let mut forge = Forge::new(&config.path_to_foundry_scripts())
201208
.script(&REGISTER_CTM_SCRIPT_PARAMS.script(), forge_args.clone())
202209
.with_ffi()
210+
.with_calldata(&calldata)
203211
.with_rpc_url(l1_rpc_url.to_string());
204212

205213
if config.l1_network == L1Network::Localhost {
@@ -214,14 +222,15 @@ pub async fn register_ctm_on_existing_bh(
214222
fill_forge_private_key(forge, Some(&wallets_config.governor), WalletOwner::Governor)?;
215223
}
216224

217-
if broadcast {
225+
if !only_save_calldata {
218226
forge = forge.with_broadcast();
219227
check_the_balance(&forge).await?;
220228
}
221229

230+
let output_path = REGISTER_CTM_SCRIPT_PARAMS.output(&config.path_to_foundry_scripts());
222231
forge.run(shell)?;
223232

224-
Ok(())
233+
Ok(AdminScriptOutputInner::read(shell, output_path)?.into())
225234
}
226235

227236
pub async fn deploy_erc20(

zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ async fn init_ecosystem(
141141
let forge_args = init_args.forge_args.clone();
142142

143143
let mut reg_args = RegisterCTMArgsFinal::from((*init_args).clone());
144-
register_ctm(&mut reg_args, shell, forge_args, ecosystem_config).await?;
144+
register_ctm(&mut reg_args, shell, forge_args, ecosystem_config, false).await?;
145145

146146
Ok(contracts)
147147
}

zkstack_cli/crates/zkstack/src/commands/ecosystem/register_ctm.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::{
66
args::init::{RegisterCTMArgs, RegisterCTMArgsFinal},
77
common::register_ctm_on_existing_bh,
88
};
9-
use crate::messages::MSG_REGISTERING_CTM;
9+
use crate::{commands::chain::utils::display_admin_script_output, messages::MSG_REGISTERING_CTM};
1010

1111
pub async fn run(args: RegisterCTMArgs, shell: &Shell) -> anyhow::Result<()> {
1212
let ecosystem_config = ZkStackConfig::ecosystem(shell)?;
@@ -29,6 +29,7 @@ pub async fn run(args: RegisterCTMArgs, shell: &Shell) -> anyhow::Result<()> {
2929
shell,
3030
forge_args,
3131
&ecosystem_config,
32+
args.only_save_calldata,
3233
)
3334
.await?;
3435

@@ -40,16 +41,20 @@ pub async fn register_ctm(
4041
shell: &Shell,
4142
forge_args: ForgeScriptArgs,
4243
ecosystem_config: &EcosystemConfig,
44+
only_save_calldata: bool,
4345
) -> anyhow::Result<()> {
44-
register_ctm_on_existing_bh(
46+
let output = register_ctm_on_existing_bh(
4547
shell,
4648
&forge_args,
4749
ecosystem_config,
4850
&init_args.ecosystem.l1_rpc_url,
4951
None,
50-
true,
52+
only_save_calldata,
5153
)
5254
.await?;
5355

56+
if only_save_calldata {
57+
display_admin_script_output(output);
58+
}
5459
Ok(())
5560
}

0 commit comments

Comments
 (0)