From 4803e691d79d34b35d78d67b097b44000ea7614f Mon Sep 17 00:00:00 2001 From: satan Date: Wed, 11 Sep 2024 12:01:34 +0200 Subject: [PATCH 1/2] Validate nam has masp params at genesis --- crates/node/src/shell/init_chain.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/crates/node/src/shell/init_chain.rs b/crates/node/src/shell/init_chain.rs index ca13aa6cc2..20bfc93a5a 100644 --- a/crates/node/src/shell/init_chain.rs +++ b/crates/node/src/shell/init_chain.rs @@ -51,6 +51,8 @@ enum Panic { "Config for token '{0}' with configured balance not found in genesis" )] MissingTokenConfig(String), + #[error("The MASP parameters for the native token is missing")] + MissingMaspParams, #[error("Failed to read wasm {0} with reason: {1}")] ReadingWasm(String, String), } @@ -446,6 +448,7 @@ where /// Init genesis token accounts fn init_token_accounts(&mut self, genesis: &genesis::chain::Finalized) { let mut token_map = BTreeMap::new(); + let native_alias = &genesis.parameters.parameters.native_token; for (alias, token) in &genesis.tokens.token { tracing::debug!("Initializing token {alias}"); @@ -453,6 +456,9 @@ where address, config: TokenConfig { denom, masp_params }, } = token; + if alias == native_alias && masp_params.is_none() { + self.register_err(Panic::MissingMaspParams); + } // associate a token with its denomination. write_denom(&mut self.state, address, *denom).unwrap(); namada_sdk::token::write_params( @@ -1211,4 +1217,23 @@ mod test { )]; assert_eq!(expected, initializer.warnings); } + + #[test] + fn test_dry_run_native_token_masp_params() { + let (mut shell, _x, _y, _z) = TestShell::new_at_height(0); + shell.wasm_dir = PathBuf::new(); + let mut genesis = genesis::make_dev_genesis(1, &shell.base_dir); + let mut initializer = InitChainValidation::new(&mut shell, true); + genesis + .tokens + .token + .get_mut(&genesis.parameters.parameters.native_token) + .expect("Test failed") + .config + .masp_params = None; + initializer.init_token_accounts(&genesis); + let [panic]: [Panic; 1] = + initializer.panics.clone().try_into().expect("Test failed"); + assert_eq!(panic, Panic::MissingMaspParams); + } } From ea5404a5a0517d654a6c591727fc7ec87031942d Mon Sep 17 00:00:00 2001 From: satan Date: Thu, 12 Sep 2024 08:55:00 +0200 Subject: [PATCH 2/2] Changelog --- .../unreleased/improvements/3806-validate-nam-masp-params.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/improvements/3806-validate-nam-masp-params.md diff --git a/.changelog/unreleased/improvements/3806-validate-nam-masp-params.md b/.changelog/unreleased/improvements/3806-validate-nam-masp-params.md new file mode 100644 index 0000000000..94cb6c62a4 --- /dev/null +++ b/.changelog/unreleased/improvements/3806-validate-nam-masp-params.md @@ -0,0 +1,2 @@ + - When calling init chain, we now verify that the native token alias has masp + parameters set. ([\#3806](https://github.com/anoma/namada/pull/3806)) \ No newline at end of file