Skip to content

Commit 2e32593

Browse files
committed
Now ensure that the MASP crate gets the correct key ak.
1 parent a938eb2 commit 2e32593

File tree

11 files changed

+80
-63
lines changed

11 files changed

+80
-63
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ libc = "0.2.97"
138138
libloading = "0.7.2"
139139
linkme = "0.3.24"
140140
# branch = "tomas/arbitrary"
141-
masp_primitives = { git = "https://github.com/anoma/masp", rev = "e6451ecf64d519409f9b1a67aa1d8322a9fe0717" }
142-
masp_proofs = { git = "https://github.com/anoma/masp", rev = "e6451ecf64d519409f9b1a67aa1d8322a9fe0717", default-features = false, features = ["local-prover"] }
141+
masp_primitives = { git = "https://github.com/anoma/masp", rev = "f2b0cae3e495e4f7d482e587432ec4e5f2793528" }
142+
masp_proofs = { git = "https://github.com/anoma/masp", rev = "f2b0cae3e495e4f7d482e587432ec4e5f2793528", default-features = false, features = ["local-prover"] }
143143
num256 = "0.3.5"
144144
num_cpus = "1.13.0"
145145
num-derive = "0.4"

crates/apps_lib/src/cli/context.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use namada_sdk::masp::fs::FsShieldedUtils;
1616
use namada_sdk::masp::{ShieldedContext, *};
1717
use namada_sdk::wallet::{DatedSpendingKey, DatedViewingKey, Wallet};
1818
use namada_sdk::{Namada, NamadaImpl};
19-
use masp_primitives::zip32::sapling::PseudoExtendedSpendingKey;
19+
use masp_primitives::zip32::sapling::PseudoExtendedKey;
20+
use masp_primitives::zip32::{
21+
ExtendedFullViewingKey as MaspExtendedViewingKey, ExtendedSpendingKey as MaspExtendedSpendingKey,
22+
};
2023

2124
use super::args;
2225
use crate::cli::utils;
@@ -44,7 +47,7 @@ pub type WalletAddrOrNativeToken = FromContext<AddrOrNativeToken>;
4447

4548
/// A raw extended spending key (bech32m encoding) or an alias of an extended
4649
/// spending key in the wallet
47-
pub type WalletSpendingKey = FromContext<PseudoExtendedSpendingKey>;
50+
pub type WalletSpendingKey = FromContext<PseudoExtendedKey>;
4851

4952
/// A raw dated extended spending key (bech32m encoding) or an alias of an
5053
/// extended spending key in the wallet
@@ -585,31 +588,31 @@ impl ArgFromMutContext for ExtendedSpendingKey {
585588
}
586589
}
587590

588-
impl ArgFromMutContext for PseudoExtendedSpendingKey {
591+
impl ArgFromMutContext for PseudoExtendedKey {
589592
fn arg_from_mut_ctx(
590593
ctx: &mut ChainContext,
591594
raw: impl AsRef<str>,
592595
) -> Result<Self, String> {
593596
let raw = raw.as_ref();
594597
// Either the string is a raw extended spending key
595598
ExtendedSpendingKey::from_str(raw).map(
596-
|x| PseudoExtendedSpendingKey::from_spending_key(x.into())
599+
|x| PseudoExtendedKey::from(MaspExtendedSpendingKey::from(x))
597600
).or_else(|_parse_err| {
598601
ExtendedViewingKey::from_str(raw).map(
599-
|x| PseudoExtendedSpendingKey::from_viewing_key(x.into())
602+
|x| PseudoExtendedKey::from(MaspExtendedViewingKey::from(x))
600603
)
601604
}).or_else(|_parse_err| {
602605
// Or it is a stored alias of one
603606
ctx.wallet
604607
.find_spending_key(raw, None)
605-
.map(|k| PseudoExtendedSpendingKey::from_spending_key(k.key.into()))
608+
.map(|k| PseudoExtendedKey::from(MaspExtendedSpendingKey::from(k.key)))
606609
.map_err(|_find_err| format!("Unknown spending key {}", raw))
607610
}).or_else(|_parse_err| {
608611
// Or it is a stored alias of one
609612
ctx.wallet
610613
.find_viewing_key(raw)
611614
.copied()
612-
.map(|k| PseudoExtendedSpendingKey::from_viewing_key(k.key.into()))
615+
.map(|k| PseudoExtendedKey::from(MaspExtendedViewingKey::from(k.key)))
613616
.map_err(|_find_err| format!("Unknown viewing key {}", raw))
614617
})
615618
}
@@ -694,11 +697,11 @@ impl ArgFromMutContext for TransferSource {
694697
.map(Self::Address)
695698
.or_else(|_| {
696699
ExtendedSpendingKey::arg_from_mut_ctx(ctx, raw)
697-
.map(|x| Self::ExtendedSpendingKey(PseudoExtendedSpendingKey::from_spending_key(x.into())))
700+
.map(|x| Self::ExtendedSpendingKey(PseudoExtendedKey::from(MaspExtendedSpendingKey::from(x))))
698701
})
699702
.or_else(|_| {
700703
ExtendedViewingKey::arg_from_mut_ctx(ctx, raw)
701-
.map(|x| Self::ExtendedSpendingKey(PseudoExtendedSpendingKey::from_viewing_key(x.into())))
704+
.map(|x| Self::ExtendedSpendingKey(PseudoExtendedKey::from(MaspExtendedViewingKey::from(x))))
702705
})
703706
}
704707
}

crates/apps_lib/src/client/tx.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ use namada_sdk::collections::HashMap;
2929
use masp_primitives::sapling::redjubjub;
3030
use masp_primitives::transaction::components::sapling::fees::InputView;
3131
use crate::masp_primitives::transaction::components::sapling;
32+
use masp_primitives::zip32::ExtendedKey;
33+
use masp_primitives::sapling::redjubjub::PrivateKey;
3234

3335
use masp_primitives::transaction::components::sapling::builder::{
3436
BuildParams, ConvertBuildParams, OutputBuildParams, RngBuildParams,
@@ -838,7 +840,7 @@ pub async fn submit_shielded_transfer(
838840
// Augment the pseudo spending key with a proof authorization key
839841
for data in &mut args.data {
840842
// Only attempt an augmentation if proof authorization is not there
841-
if data.source.partial_spending_key().is_none() {
843+
if data.source.to_spending_key().is_none() {
842844
// First find the derivation path corresponding to this viewing
843845
// key
844846
let viewing_key =
@@ -900,11 +902,14 @@ pub async fn submit_shielded_transfer(
900902
hardware wallet: {}.",
901903
err,
902904
)))?;
903-
// Finally augment the pseudo spending key
904-
data.source.augment(pgk).map_err(|_| error::Error::Other(format!(
905+
// Augment the pseudo spending key
906+
data.source.augment_proof_generation_key(pgk).map_err(|_| error::Error::Other(format!(
905907
"Proof generation key in response from the hardware wallet \
906908
does not correspond to stored viewing key.",
907909
)))?;
910+
// Finally, augment an incorrect spend authorization key just to
911+
// make sure that the Transaction is built.
912+
data.source.augment_spend_authorizing_key_unchecked(PrivateKey(jubjub::Fr::default()));
908913
shielded_hw_keys.insert(path.path, viewing_key);
909914
}
910915
}
@@ -988,7 +993,7 @@ pub async fn submit_shielded_transfer(
988993
for (path, vk) in shielded_hw_keys {
989994
// Sign the MASP Transaction using the current viewing key
990995
let path = BIP44Path { path: path.to_string() };
991-
let response = app
996+
app
992997
.sign_masp(&path, &tx.serialize_to_vec())
993998
.await
994999
.map_err(|err| error::Error::Other(err.to_string()))?;
@@ -1027,6 +1032,8 @@ pub async fn submit_shielded_transfer(
10271032
err,
10281033
)))?;
10291034
}
1035+
tx.remove_masp_section(&shielded_hash);
1036+
tx.add_section(Section::MaspTx(masp_tx));
10301037
}
10311038
sign(namada, &mut tx, &args.tx, signing_data).await?;
10321039
namada.submit(tx, &args.tx).await?;

crates/core/src/masp.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use borsh_ext::BorshSerializeExt;
1010
use masp_primitives::asset_type::AssetType;
1111
use masp_primitives::sapling::ViewingKey;
1212
use masp_primitives::transaction::TransparentAddress;
13-
use masp_primitives::zip32::sapling::PseudoExtendedSpendingKey;
13+
use masp_primitives::zip32::sapling::PseudoExtendedKey;
14+
use masp_primitives::zip32::ExtendedKey;
1415
pub use masp_primitives::transaction::TxId as TxIdInner;
1516
use namada_macros::BorshDeserializer;
1617
#[cfg(feature = "migrations")]
@@ -68,7 +69,7 @@ pub struct MaspTxId(
6869
serialize_with = "serialize_txid",
6970
deserialize_with = "deserialize_txid"
7071
)]
71-
TxIdInner,
72+
pub TxIdInner,
7273
);
7374

7475
impl From<TxIdInner> for MaspTxId {
@@ -518,7 +519,7 @@ pub enum TransferSource {
518519
/// A transfer coming from a transparent address
519520
Address(Address),
520521
/// A transfer coming from a shielded address
521-
ExtendedSpendingKey(PseudoExtendedSpendingKey),
522+
ExtendedSpendingKey(PseudoExtendedKey),
522523
}
523524

524525
impl TransferSource {
@@ -533,7 +534,7 @@ impl TransferSource {
533534
}
534535

535536
/// Get the contained ExtendedSpendingKey contained, if any
536-
pub fn spending_key(&self) -> Option<PseudoExtendedSpendingKey> {
537+
pub fn spending_key(&self) -> Option<PseudoExtendedKey> {
537538
match self {
538539
Self::ExtendedSpendingKey(x) => Some(*x),
539540
_ => None,

crates/sdk/src/args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::str::FromStr;
66
use std::time::Duration as StdDuration;
77

88
use masp_primitives::transaction::components::sapling::builder::BuildParams;
9-
use masp_primitives::zip32::sapling::PseudoExtendedSpendingKey;
9+
use masp_primitives::zip32::sapling::PseudoExtendedKey;
1010

1111
use namada_core::address::Address;
1212
use namada_core::chain::{BlockHeight, ChainId, Epoch};
@@ -121,7 +121,7 @@ impl NamadaTypes for SdkTypes {
121121
type MaspIndexerAddress = String;
122122
type PaymentAddress = namada_core::masp::PaymentAddress;
123123
type PublicKey = namada_core::key::common::PublicKey;
124-
type SpendingKey = PseudoExtendedSpendingKey;
124+
type SpendingKey = PseudoExtendedKey;
125125
type TendermintAddress = tendermint_rpc::Url;
126126
type TransferSource = namada_core::masp::TransferSource;
127127
type TransferTarget = namada_core::masp::TransferTarget;

crates/sdk/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub use std::marker::Sync as MaybeSync;
5151
use std::path::PathBuf;
5252
use std::str::FromStr;
5353

54-
use masp_primitives::zip32::sapling::PseudoExtendedSpendingKey;
54+
use masp_primitives::zip32::sapling::PseudoExtendedKey;
5555
use args::{DeviceTransport, InputAmount, SdkTypes};
5656
use io::Io;
5757
use masp::{ShieldedContext, ShieldedUtils};
@@ -62,7 +62,7 @@ use namada_core::dec::Dec;
6262
use namada_core::ethereum_events::EthAddress;
6363
use namada_core::ibc::core::host::types::identifiers::{ChannelId, PortId};
6464
use namada_core::key::*;
65-
use namada_core::masp::{ExtendedSpendingKey, PaymentAddress, TransferSource};
65+
use namada_core::masp::{PaymentAddress, TransferSource};
6666
use namada_tx::data::wrapper::GasLimit;
6767
use namada_tx::Tx;
6868
use rpc::{denominate_amount, format_denominated_amount, query_native_token};
@@ -190,7 +190,7 @@ pub trait Namada: Sized + MaybeSync + MaybeSend {
190190
fn new_shielded_transfer(
191191
&self,
192192
data: Vec<args::TxShieldedTransferData>,
193-
gas_spending_keys: Vec<PseudoExtendedSpendingKey>,
193+
gas_spending_keys: Vec<PseudoExtendedKey>,
194194
disposable_signing_key: bool,
195195
) -> args::TxShieldedTransfer {
196196
args::TxShieldedTransfer {
@@ -221,9 +221,9 @@ pub trait Namada: Sized + MaybeSync + MaybeSend {
221221
/// arguments
222222
fn new_unshielding_transfer(
223223
&self,
224-
source: PseudoExtendedSpendingKey,
224+
source: PseudoExtendedKey,
225225
data: Vec<args::TxUnshieldingTransferData>,
226-
gas_spending_keys: Vec<PseudoExtendedSpendingKey>,
226+
gas_spending_keys: Vec<PseudoExtendedKey>,
227227
disposable_signing_key: bool,
228228
) -> args::TxUnshieldingTransfer {
229229
args::TxUnshieldingTransfer {

0 commit comments

Comments
 (0)