From c36dc61c3e72a258801d600f63dc30daf2ffc3a8 Mon Sep 17 00:00:00 2001 From: spidey-169 Date: Wed, 21 Feb 2024 00:50:57 -0600 Subject: [PATCH 1/6] Adding check on Client side to ensure Threshold < Noof Public Keys during updateAccount Throwing a panic error if condition isn't met so the user accidently doesn't end up changing threshold to be above the number of public keys. Also minor grammatical error corrections --- crates/apps/src/lib/cli.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/crates/apps/src/lib/cli.rs b/crates/apps/src/lib/cli.rs index 3e84538f0f..551ab6cf6c 100644 --- a/crates/apps/src/lib/cli.rs +++ b/crates/apps/src/lib/cli.rs @@ -4088,7 +4088,7 @@ pub mod args { )) .arg(THRESHOLD.def().help( "The minimum number of signature to be provided for \ - authorization. Must be less then the maximum number of \ + authorization. Must be less than the maximum number of \ public keys provided.", )) } @@ -4390,6 +4390,13 @@ pub mod args { let tx_code_path = PathBuf::from(TX_UPDATE_ACCOUNT_WASM); let public_keys = PUBLIC_KEYS.parse(matches); let threshold = THRESHOLD.parse(matches); + + // Custom validation to enforce threshold < number of public keys + if threshold > public_keys.len() as u8 { + // Threshold should be less than the number of public keys + panic!("Threshold must be less than the number of public keys"); + } + Self { tx, vp_code_path, @@ -4399,17 +4406,14 @@ pub mod args { threshold, } } - + fn def(app: App) -> App { app.add_args::>() - .arg( - CODE_PATH_OPT.def().help( - "The path to the new validity predicate WASM code.", - ), - ) + .arg(CODE_PATH_OPT.def().help( + "The path to the new validity predicate WASM code.", + )) .arg(ADDRESS.def().help( - "The account's address. It's key is used to produce the \ - signature.", + "The account's address. It's key is used to produce the signature.", )) .arg(PUBLIC_KEYS.def().help( "A list public keys to be associated with the new account \ @@ -4417,11 +4421,13 @@ pub mod args { )) .arg(THRESHOLD.def().help( "The minimum number of signature to be provided for \ - authorization. Must be less then the maximum number of \ + authorization. Must be less than the maximum number of \ public keys provided.", )) } } + + impl CliToSdk> for Bond { fn to_sdk(self, ctx: &mut Context) -> Bond { From a952d1a94da38b8978a4e1dbd33c830363ace915 Mon Sep 17 00:00:00 2001 From: spidey-169 Date: Wed, 21 Feb 2024 01:14:10 -0600 Subject: [PATCH 2/6] Adding changelog --- .../improvements/2677-update-account-threshold-check.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/improvements/2677-update-account-threshold-check.md diff --git a/.changelog/unreleased/improvements/2677-update-account-threshold-check.md b/.changelog/unreleased/improvements/2677-update-account-threshold-check.md new file mode 100644 index 0000000000..cd03842f50 --- /dev/null +++ b/.changelog/unreleased/improvements/2677-update-account-threshold-check.md @@ -0,0 +1,2 @@ +- Added Client check to not allow --threshold to be great than No.of Public keys in update-account call + ([\#2677](https://github.com/anoma/namada/pull/2677)) \ No newline at end of file From b72acc158d87a5d9eee08d75e592832d33c97224 Mon Sep 17 00:00:00 2001 From: spidey-169 Date: Wed, 21 Feb 2024 01:14:20 -0600 Subject: [PATCH 3/6] Grammatical fix --- crates/apps/src/lib/cli.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/apps/src/lib/cli.rs b/crates/apps/src/lib/cli.rs index 551ab6cf6c..716a9735ee 100644 --- a/crates/apps/src/lib/cli.rs +++ b/crates/apps/src/lib/cli.rs @@ -4357,7 +4357,7 @@ pub mod args { )) .arg(THRESHOLD.def().help( "The minimum number of signature to be provided for \ - authorization. Must be less then the maximum number of \ + authorization. Must be less than the maximum number of \ public keys provided.", )) } From 2e3b3e8eb116e475fec40dc728ca550ebec85cc5 Mon Sep 17 00:00:00 2001 From: spidey-169 Date: Wed, 21 Feb 2024 01:56:52 -0600 Subject: [PATCH 4/6] Correcting u8 to Option --- crates/apps/src/lib/cli.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/apps/src/lib/cli.rs b/crates/apps/src/lib/cli.rs index 716a9735ee..c31f40b028 100644 --- a/crates/apps/src/lib/cli.rs +++ b/crates/apps/src/lib/cli.rs @@ -4392,7 +4392,7 @@ pub mod args { let threshold = THRESHOLD.parse(matches); // Custom validation to enforce threshold < number of public keys - if threshold > public_keys.len() as u8 { + if threshold > public_keys.len() as Option { // Threshold should be less than the number of public keys panic!("Threshold must be less than the number of public keys"); } From 52d68532a9cb1be63cfa6fa0c3526e5d71f36018 Mon Sep 17 00:00:00 2001 From: spidey-169 Date: Wed, 21 Feb 2024 02:12:38 -0600 Subject: [PATCH 5/6] Changing logic for check. Comparing num_keys with threshold --- crates/apps/src/lib/cli.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/apps/src/lib/cli.rs b/crates/apps/src/lib/cli.rs index c31f40b028..350551a515 100644 --- a/crates/apps/src/lib/cli.rs +++ b/crates/apps/src/lib/cli.rs @@ -4391,10 +4391,11 @@ pub mod args { let public_keys = PUBLIC_KEYS.parse(matches); let threshold = THRESHOLD.parse(matches); - // Custom validation to enforce threshold < number of public keys - if threshold > public_keys.len() as Option { - // Threshold should be less than the number of public keys - panic!("Threshold must be less than the number of public keys"); + let num_keys = public_keys.as_ref().map_or(0, |keys| keys.len()); + + if num_keys < threshold { + eprintln!("Threshold must be less than the number of public keys provided."); + std::process::exit(1); } Self { From 8c2eaecfc68d36767eaf7896b5b08ea2885f1239 Mon Sep 17 00:00:00 2001 From: spidey-169 Date: Wed, 21 Feb 2024 20:27:15 -0600 Subject: [PATCH 6/6] Adding changes recommended for defininig num_keys --- crates/apps/src/lib/cli.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/apps/src/lib/cli.rs b/crates/apps/src/lib/cli.rs index 350551a515..910044b240 100644 --- a/crates/apps/src/lib/cli.rs +++ b/crates/apps/src/lib/cli.rs @@ -4391,8 +4391,7 @@ pub mod args { let public_keys = PUBLIC_KEYS.parse(matches); let threshold = THRESHOLD.parse(matches); - let num_keys = public_keys.as_ref().map_or(0, |keys| keys.len()); - + let num_keys = > as AsRef>::as_ref(&public_keys).map_or(0, |keys| keys.len()); if num_keys < threshold { eprintln!("Threshold must be less than the number of public keys provided."); std::process::exit(1);