Skip to content

Commit

Permalink
Merge branch 'murisi/multisig-fixes' (#1884)
Browse files Browse the repository at this point in the history
* origin/murisi/multisig-fixes:
  Added changelog entry.
  Added support for compressed signatures coming from hardware wallets.
  Combining Signature and MultiSignature sections to deduplicate hardware wallet code.
  Allow public key to be specified in signature section.
  • Loading branch information
Fraccaman committed Sep 25, 2023
2 parents 1eb9ad9 + 6eff4a9 commit 640bd1a
Show file tree
Hide file tree
Showing 42 changed files with 1,121 additions and 430 deletions.
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 @@ -261,7 +261,7 @@ impl<IO: Io> CliApi<IO> {
&client,
&mut ctx.wallet,
&args.tx,
&Some(args.sender.clone()),
Some(args.sender.clone()),
default_signer,
)
.await?;
Expand Down
55 changes: 28 additions & 27 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub async fn aux_signing_data<
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 = signing::aux_signing_data::<_, _, IO>(
Expand Down Expand Up @@ -105,7 +105,7 @@ pub async fn submit_reveal_aux<
client,
&mut ctx.wallet,
&args,
&None,
None,
None,
)
.await?;
Expand Down Expand Up @@ -152,7 +152,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(args.owner.clone()),
Some(args.owner.clone()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -197,7 +197,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(args.addr.clone()),
Some(args.addr.clone()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -238,7 +238,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&None,
None,
None,
)
.await?;
Expand Down Expand Up @@ -476,7 +476,7 @@ where
client,
&mut ctx.wallet,
&tx_args,
&None,
None,
None,
)
.await?;
Expand Down Expand Up @@ -719,7 +719,7 @@ pub async fn submit_transfer<
client,
&mut ctx.wallet,
&args.tx,
&Some(args.source.effective_address()),
Some(args.source.effective_address()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -800,7 +800,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(args.source.clone()),
Some(args.source.clone()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -859,7 +859,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(proposal.author.clone()),
Some(proposal.author.clone()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -894,7 +894,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 @@ -946,7 +946,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 @@ -996,7 +996,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 @@ -1066,7 +1066,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(args.voter.clone()),
Some(args.voter.clone()),
default_signer.clone(),
)
.await?;
Expand Down Expand Up @@ -1176,7 +1176,7 @@ where
client,
&mut ctx.wallet,
&tx_args,
&Some(owner),
Some(owner.clone()),
default_signer,
)
.await?;
Expand All @@ -1203,14 +1203,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 @@ -1228,9 +1231,7 @@ where
display_line!(
IO,
"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 @@ -1273,7 +1274,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(default_address.clone()),
Some(default_address.clone()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -1319,7 +1320,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(default_address),
Some(default_address),
default_signer,
)
.await?;
Expand Down Expand Up @@ -1366,7 +1367,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(default_address),
Some(default_address),
default_signer,
)
.await?;
Expand Down Expand Up @@ -1407,7 +1408,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(args.validator.clone()),
Some(args.validator.clone()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -1452,7 +1453,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(args.validator.clone()),
Some(args.validator.clone()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -1498,7 +1499,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(args.steward.clone()),
Some(args.steward.clone()),
default_signer,
)
.await?;
Expand Down Expand Up @@ -1541,7 +1542,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 @@ -1126,7 +1126,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 @@ -2440,7 +2441,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 @@ -2511,7 +2513,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 @@ -2593,7 +2596,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 @@ -2233,7 +2233,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 @@ -2314,7 +2315,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 @@ -2380,7 +2382,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 @@ -2537,7 +2540,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 @@ -2569,7 +2573,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 @@ -2601,7 +2606,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 @@ -2633,7 +2641,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 @@ -2664,7 +2675,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 @@ -2695,7 +2709,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

0 comments on commit 640bd1a

Please sign in to comment.