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

Nondegenerate multisignature hardware wallets #1884

Merged
merged 4 commits into from
Sep 25, 2023
Merged
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
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/1884-multisig-fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Enable hardware wallets to participate in nondegenerate multisignature
transactions. ([\#1884](https://github.com/anoma/namada/pull/1884))
2 changes: 1 addition & 1 deletion apps/src/lib/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl<IO> CliApi<IO> {
&client,
&mut ctx.wallet,
&args.tx,
&Some(args.sender.clone()),
Some(args.sender.clone()),
default_signer,
)
.await?;
Expand Down
57 changes: 28 additions & 29 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub async fn aux_signing_data<C: namada::ledger::queries::Client + Sync>(
client: &C,
wallet: &mut Wallet<CliWalletUtils>,
args: &args::Tx,
owner: &Option<Address>,
owner: Option<Address>,
default_signer: Option<Address>,
) -> Result<signing::SigningTxData, error::Error> {
let signing_data =
Expand Down Expand Up @@ -88,7 +88,7 @@ pub async fn submit_reveal_aux<C: namada::ledger::queries::Client + Sync>(

if tx::is_reveal_pk_needed::<C>(client, address, args.force).await? {
let signing_data =
aux_signing_data(client, &mut ctx.wallet, &args, &None, None)
aux_signing_data(client, &mut ctx.wallet, &args, None, None)
.await?;

let (mut tx, _epoch) = tx::build_reveal_pk(
Expand Down Expand Up @@ -126,7 +126,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(args.owner.clone()),
Some(args.owner.clone()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -168,7 +168,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(args.addr.clone()),
Some(args.addr.clone()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -203,8 +203,7 @@ where
C::Error: std::fmt::Display,
{
let signing_data =
aux_signing_data(client, &mut ctx.wallet, &args.tx, &None, None)
.await?;
aux_signing_data(client, &mut ctx.wallet, &args.tx, None, None).await?;

let (mut tx, _epoch) = tx::build_init_account(
client,
Expand Down Expand Up @@ -429,8 +428,7 @@ pub async fn submit_init_validator<
tx.add_code_from_hash(tx_code_hash).add_data(data);

let signing_data =
aux_signing_data(client, &mut ctx.wallet, &tx_args, &None, None)
.await?;
aux_signing_data(client, &mut ctx.wallet, &tx_args, None, None).await?;

tx::prepare_tx(
client,
Expand Down Expand Up @@ -647,7 +645,7 @@ pub async fn submit_transfer<C: namada::ledger::queries::Client + Sync>(
client,
&mut ctx.wallet,
&args.tx,
&Some(args.source.effective_address()),
Some(args.source.effective_address()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -720,7 +718,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(args.source.clone()),
Some(args.source.clone()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -775,7 +773,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(proposal.author.clone()),
Some(proposal.author.clone()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -810,7 +808,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(proposal.proposal.author.clone()),
Some(proposal.proposal.author.clone()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -862,7 +860,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(proposal.proposal.author.clone()),
Some(proposal.proposal.author.clone()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -912,7 +910,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(proposal.proposal.author.clone()),
Some(proposal.proposal.author.clone()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -971,7 +969,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(args.voter.clone()),
Some(args.voter.clone()),
default_signer.clone(),
)
.await?;
Expand Down Expand Up @@ -1070,7 +1068,7 @@ where
client,
&mut ctx.wallet,
&tx_args,
&Some(owner),
Some(owner.clone()),
default_signer,
)
.await?;
Expand All @@ -1096,14 +1094,17 @@ where

if let Some(account_public_keys_map) = signing_data.account_public_keys_map
{
let signatures =
tx.compute_section_signature(secret_keys, &account_public_keys_map);
let signatures = tx.compute_section_signature(
secret_keys,
&account_public_keys_map,
Some(owner),
);

for signature in &signatures {
let filename = format!(
"offline_signature_{}_{}.tx",
tx.header_hash(),
signature.index
signature.pubkey,
);
let output_path = match &tx_args.output_folder {
Some(path) => path.join(filename),
Expand All @@ -1120,9 +1121,7 @@ where
.expect("Signature should be deserializable.");
println!(
"Signature for {} serialized at {}",
&account_public_keys_map
.get_public_key_from_index(signature.index)
.unwrap(),
signature.pubkey,
output_path.display()
);
}
Expand Down Expand Up @@ -1158,7 +1157,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(default_address.clone()),
Some(default_address.clone()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -1200,7 +1199,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(default_address),
Some(default_address),
default_signer,
)
.await?;
Expand Down Expand Up @@ -1243,7 +1242,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(default_address),
Some(default_address),
default_signer,
)
.await?;
Expand Down Expand Up @@ -1284,7 +1283,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(args.validator.clone()),
Some(args.validator.clone()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -1325,7 +1324,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(args.validator.clone()),
Some(args.validator.clone()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -1367,7 +1366,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(args.steward.clone()),
Some(args.steward.clone()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -1407,7 +1406,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(args.steward.clone()),
Some(args.steward.clone()),
default_signer,
)
.await?;
Expand Down
14 changes: 10 additions & 4 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,8 @@ mod test_finalize_block {
));
wrapper_tx.add_section(Section::Signature(Signature::new(
wrapper_tx.sechashes(),
keypair,
[(0, keypair.clone())].into_iter().collect(),
None,
)));
let tx = wrapper_tx.to_bytes();
(
Expand Down Expand Up @@ -2489,7 +2490,8 @@ mod test_finalize_block {
));
wrapper.add_section(Section::Signature(Signature::new(
wrapper.sechashes(),
&keypair,
[(0, keypair)].into_iter().collect(),
None,
)));

let wrapper_hash_key = replay_protection::get_replay_protection_key(
Expand Down Expand Up @@ -2562,7 +2564,8 @@ mod test_finalize_block {
));
wrapper.add_section(Section::Signature(Signature::new(
wrapper.sechashes(),
&keypair,
[(0, keypair.clone())].into_iter().collect(),
None,
)));

let processed_tx = ProcessedTx {
Expand Down Expand Up @@ -2646,7 +2649,10 @@ mod test_finalize_block {
));
wrapper.add_section(Section::Signature(Signature::new(
wrapper.sechashes(),
&crate::wallet::defaults::albert_keypair(),
[(0, crate::wallet::defaults::albert_keypair())]
.into_iter()
.collect(),
None,
)));
let fee_amount =
wrapper.header().wrapper().unwrap().get_tx_fee().unwrap();
Expand Down
35 changes: 26 additions & 9 deletions apps/src/lib/node/ledger/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2299,7 +2299,8 @@ mod abciplus_mempool_tests {
tx.set_data(Data::new(ext.try_to_vec().expect("Test falied")));
tx.add_section(Section::Signature(Signature::new(
tx.sechashes(),
&protocol_key,
[(0, protocol_key)].into_iter().collect(),
None,
)));
tx
}
Expand Down Expand Up @@ -2384,7 +2385,8 @@ mod test_mempool_validate {
.set_data(Data::new("transaction data".as_bytes().to_owned()));
invalid_wrapper.add_section(Section::Signature(Signature::new(
invalid_wrapper.sechashes(),
&keypair,
[(0, keypair)].into_iter().collect(),
None,
)));

// we mount a malleability attack to try and remove the fee
Expand Down Expand Up @@ -2452,7 +2454,8 @@ mod test_mempool_validate {
wrapper.set_data(Data::new("transaction data".as_bytes().to_owned()));
wrapper.add_section(Section::Signature(Signature::new(
wrapper.sechashes(),
&keypair,
[(0, keypair)].into_iter().collect(),
None,
)));

// Write wrapper hash to storage
Expand Down Expand Up @@ -2611,7 +2614,8 @@ mod test_mempool_validate {
wrapper.set_data(Data::new("transaction data".as_bytes().to_owned()));
wrapper.add_section(Section::Signature(Signature::new(
wrapper.sechashes(),
&keypair,
[(0, keypair)].into_iter().collect(),
None,
)));

let result = shell.mempool_validate(
Expand Down Expand Up @@ -2645,7 +2649,8 @@ mod test_mempool_validate {
wrapper.set_data(Data::new("transaction data".as_bytes().to_owned()));
wrapper.add_section(Section::Signature(Signature::new(
wrapper.sechashes(),
&keypair,
[(0, keypair)].into_iter().collect(),
None,
)));

let result = shell.mempool_validate(
Expand Down Expand Up @@ -2679,7 +2684,10 @@ mod test_mempool_validate {
wrapper.set_data(Data::new("transaction data".as_bytes().to_owned()));
wrapper.add_section(Section::Signature(Signature::new(
wrapper.sechashes(),
&crate::wallet::defaults::albert_keypair(),
[(0, crate::wallet::defaults::albert_keypair())]
.into_iter()
.collect(),
None,
)));

let result = shell.mempool_validate(
Expand Down Expand Up @@ -2713,7 +2721,10 @@ mod test_mempool_validate {
wrapper.set_data(Data::new("transaction data".as_bytes().to_owned()));
wrapper.add_section(Section::Signature(Signature::new(
wrapper.sechashes(),
&crate::wallet::defaults::albert_keypair(),
[(0, crate::wallet::defaults::albert_keypair())]
.into_iter()
.collect(),
None,
)));

let result = shell.mempool_validate(
Expand Down Expand Up @@ -2746,7 +2757,10 @@ mod test_mempool_validate {
wrapper.set_data(Data::new("transaction data".as_bytes().to_owned()));
wrapper.add_section(Section::Signature(Signature::new(
wrapper.sechashes(),
&crate::wallet::defaults::albert_keypair(),
[(0, crate::wallet::defaults::albert_keypair())]
.into_iter()
.collect(),
None,
)));

let result = shell.mempool_validate(
Expand Down Expand Up @@ -2779,7 +2793,10 @@ mod test_mempool_validate {
wrapper.set_data(Data::new("transaction data".as_bytes().to_owned()));
wrapper.add_section(Section::Signature(Signature::new(
wrapper.sechashes(),
&crate::wallet::defaults::albert_keypair(),
[(0, crate::wallet::defaults::albert_keypair())]
.into_iter()
.collect(),
None,
)));

let result = shell.mempool_validate(
Expand Down
Loading