Skip to content

Commit

Permalink
Allow public key to be specified in signature section.
Browse files Browse the repository at this point in the history
  • Loading branch information
murisi committed Sep 11, 2023
1 parent 9b67281 commit ad6734d
Show file tree
Hide file tree
Showing 25 changed files with 323 additions and 216 deletions.
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
50 changes: 24 additions & 26 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,7 +203,7 @@ where
C::Error: std::fmt::Display,
{
let signing_data =
aux_signing_data(client, &mut ctx.wallet, &args.tx, &None, None)
aux_signing_data(client, &mut ctx.wallet, &args.tx, None, None)
.await?;

let (mut tx, _epoch) = tx::build_init_account(
Expand Down Expand Up @@ -429,7 +429,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)
aux_signing_data(client, &mut ctx.wallet, &tx_args, None, None)
.await?;

tx::prepare_tx(
Expand Down Expand Up @@ -647,7 +647,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 +720,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 +775,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 +810,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 +862,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 +912,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 +971,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 +1070,7 @@ where
client,
&mut ctx.wallet,
&tx_args,
&Some(owner),
Some(owner.clone()),
default_signer,
)
.await?;
Expand All @@ -1097,13 +1097,13 @@ 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);
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 +1120,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 +1156,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 +1198,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(default_address),
Some(default_address),
default_signer,
)
.await?;
Expand Down Expand Up @@ -1243,7 +1241,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(default_address),
Some(default_address),
default_signer,
)
.await?;
Expand Down Expand Up @@ -1284,7 +1282,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 +1323,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 +1365,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 +1405,7 @@ where
client,
&mut ctx.wallet,
&args.tx,
&Some(args.steward.clone()),
Some(args.steward.clone()),
default_signer,
)
.await?;
Expand Down
10 changes: 5 additions & 5 deletions benches/host_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use namada::core::types::address;
use namada::core::types::token::{Amount, Transfer};
use namada::proto::{Data, MultiSignature, Section};
use namada_apps::wallet::defaults;
use std::collections::HashSet;

/// Benchmarks the validation of a single signature on a single `Section` of a
/// transaction
Expand All @@ -26,15 +27,14 @@ fn tx_section_signature_validation(c: &mut Criterion) {

let multisig = MultiSignature::new(
vec![section_hash],
&[defaults::albert_keypair()],
&pkim,
pkim.index_secret_keys(vec![defaults::albert_keypair()]),
None,
);
let signature_index = multisig.signatures.first().unwrap().clone();

c.bench_function("tx_section_signature_validation", |b| {
b.iter(|| {
signature_index
.verify(&pkim, &multisig.get_raw_hash())
multisig
.verify_signature(&mut HashSet::new(), &pkim)
.unwrap()
})
});
Expand Down
22 changes: 7 additions & 15 deletions core/src/ledger/governance/cli/offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,18 +315,12 @@ fn compute_signatures_index(
account_public_keys_map: &AccountPublicKeysMap,
hashed_data: &Hash,
) -> BTreeSet<SignatureIndex> {
keys.iter()
.filter_map(|signing_key| {
account_public_keys_map.index_secret_keys(keys.to_vec()).values()
.map(|signing_key| {
let public_key = signing_key.ref_to();
let public_key_index =
account_public_keys_map.get_index_from_public_key(&public_key);
if public_key_index.is_some() {
let signature =
common::SigScheme::sign(signing_key, hashed_data);
Some(SignatureIndex::from_single_signature(signature))
} else {
None
}
let signature =
common::SigScheme::sign(signing_key, hashed_data);
SignatureIndex::from_single_signature(public_key, signature)
})
.collect::<BTreeSet<SignatureIndex>>()
}
Expand All @@ -338,11 +332,9 @@ fn compute_total_valid_signatures(
hashed_data: &Hash,
) -> u8 {
signatures.iter().fold(0_u8, |acc, signature_index| {
let public_key = account_public_keys_map
.get_public_key_from_index(signature_index.index);
if let Some(pk) = public_key {
if account_public_keys_map.get_index_from_public_key(&signature_index.pubkey).is_some() {
let sig_check = common::SigScheme::verify_signature(
&pk,
&signature_index.pubkey,
hashed_data,
&signature_index.signature,
);
Expand Down
Loading

0 comments on commit ad6734d

Please sign in to comment.