Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge queue: embarking main (9de7de0), #3730 and #3779 together #3786

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/unreleased/bug-fixes/3730-enable-hw-fallback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Enable the signing logic to fall back to the hardware wallet
if a secret key is not found in software wallet store.
([\#3730](https://github.com/anoma/namada/pull/3730))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Check the string length of the validator name in provided metadata.
([\#3779](https://github.com/anoma/namada/pull/3779))
9 changes: 9 additions & 0 deletions crates/apps_lib/src/config/genesis/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,15 @@ pub fn validate_validator_account(
);
}
}
if let Some(name) = metadata.name.as_ref() {
if name.len() as u64 > MAX_VALIDATOR_METADATA_LEN {
panic!(
"The name metadata of the validator with address {} is too \
long, must be within {MAX_VALIDATOR_METADATA_LEN} characters",
signed_tx.data.address
);
}
}

// Check signature
let mut is_valid = {
Expand Down
42 changes: 37 additions & 5 deletions crates/sdk/src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,13 @@ where

for public_key in &signing_data.public_keys {
if !used_pubkeys.contains(public_key) {
let secret_key = find_key_by_pk(&mut wallet, args, public_key)?;
let Ok(secret_key) =
find_key_by_pk(&mut wallet, args, public_key)
else {
// If the secret key is not found, continue because the
// hardware wallet may still be able to sign this
continue;
};
used_pubkeys.insert(public_key.clone());
signing_tx_keypairs.push(secret_key);
}
Expand All @@ -248,8 +254,8 @@ where
}

// Then try to sign the raw header using the hardware wallet
for pubkey in signing_data.public_keys {
if !used_pubkeys.contains(&pubkey) && pubkey != signing_data.fee_payer {
for pubkey in &signing_data.public_keys {
if !used_pubkeys.contains(pubkey) && *pubkey != signing_data.fee_payer {
if let Ok(ntx) = sign(
tx.clone(),
pubkey.clone(),
Expand All @@ -276,17 +282,43 @@ where
Ok(fee_payer_keypair) => {
tx.sign_wrapper(fee_payer_keypair);
}
Err(_) => {
// The case where tge fee payer also signs the inner transaction
Err(_)
if signing_data.public_keys.contains(&signing_data.fee_payer) =>
{
*tx = sign(
tx.clone(),
signing_data.fee_payer.clone(),
HashSet::from([Signable::FeeHeader, Signable::RawHeader]),
user_data,
)
.await?;
used_pubkeys.insert(signing_data.fee_payer.clone());
}
// The case where the fee payer does not sign the inner transaction
Err(_) => {
*tx = sign(
tx.clone(),
signing_data.fee_payer.clone(),
HashSet::from([Signable::FeeHeader]),
user_data,
)
.await?;
}
}
Ok(())
// Then make sure that the number of public keys used exceeds the threshold
let used_pubkeys_len = used_pubkeys
.len()
.try_into()
.expect("Public keys associated with account exceed 127");
if used_pubkeys_len < signing_data.threshold {
Err(Error::from(TxSubmitError::MissingSigningKeys(
signing_data.threshold,
used_pubkeys_len,
)))
} else {
Ok(())
}
}

/// Return the necessary data regarding an account to be able to generate a
Expand Down
12 changes: 12 additions & 0 deletions crates/sdk/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,18 @@ pub async fn build_validator_metadata_change(
}
}
}
if let Some(name) = name.as_ref() {
if name.len() as u64 > MAX_VALIDATOR_METADATA_LEN {
edisplay_line!(
context.io(),
"Name provided is too long, must be within \
{MAX_VALIDATOR_METADATA_LEN} characters"
);
if !tx_args.force {
return Err(Error::from(TxSubmitError::MetadataTooLong));
}
}
}

// If there's a new commission rate, it must be valid
if let Some(rate) = commission_rate.as_ref() {
Expand Down
Loading