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

Remove MASP pin key #3142

Merged
merged 7 commits into from
May 9, 2024
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/2675-remove-pin-key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Removed the MASP pin key.
([\#2675](https://github.com/anoma/namada/issues/2675))
3 changes: 1 addition & 2 deletions crates/apps/src/lib/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ impl Default for BenchShieldedCtx {
.wallet
.insert_payment_addr(
alias,
PaymentAddress::from(payment_addr).pinned(false),
PaymentAddress::from(payment_addr),
true,
)
.unwrap();
Expand Down Expand Up @@ -1086,7 +1086,6 @@ impl BenchShieldedCtx {
} else {
DenominatedAmount::native(amount)
},
key: None,
shielded: shielded_section_hash,
},
shielded,
Expand Down
8 changes: 0 additions & 8 deletions crates/apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3184,7 +3184,6 @@ pub mod args {
pub const OWNER: Arg<WalletAddress> = arg("owner");
pub const OWNER_OPT: ArgOpt<WalletAddress> = OWNER.opt();
pub const PATH: Arg<PathBuf> = arg("path");
pub const PIN: ArgFlag = flag("pin");
pub const PORT_ID: ArgDefault<PortId> = arg_default(
"port-id",
DefaultFn(|| PortId::from_str("transfer").unwrap()),
Expand Down Expand Up @@ -6461,7 +6460,6 @@ pub mod args {
alias: self.alias,
alias_force: self.alias_force,
viewing_key,
pin: self.pin,
}
}
}
Expand All @@ -6471,12 +6469,10 @@ pub mod args {
let alias = ALIAS.parse(matches);
let alias_force = ALIAS_FORCE.parse(matches);
let viewing_key = VIEWING_KEY.parse(matches);
let pin = PIN.parse(matches);
Self {
alias,
alias_force,
viewing_key,
pin,
}
}

Expand All @@ -6490,10 +6486,6 @@ pub mod args {
"Override the alias without confirmation if it already exists.",
))
.arg(VIEWING_KEY.def().help("The viewing key."))
.arg(PIN.def().help(
"Require that the single transaction to this address be \
pinned.",
))
}
}

Expand Down
3 changes: 0 additions & 3 deletions crates/apps/src/lib/cli/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,5 @@ impl ArgFromMutContext for BalanceOwner {
ExtendedViewingKey::arg_from_mut_ctx(ctx, raw)
.map(Self::FullViewingKey)
})
.or_else(|_| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it was only used for the pinned balance

PaymentAddress::arg_from_ctx(ctx, raw).map(Self::PaymentAddress)
})
}
}
3 changes: 1 addition & 2 deletions crates/apps/src/lib/cli/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ fn payment_address_gen(
alias,
alias_force,
viewing_key,
pin,
..
}: args::PayAddressGen,
) {
Expand All @@ -326,7 +325,7 @@ fn payment_address_gen(
let masp_payment_addr = viewing_key
.to_payment_address(div)
.expect("a PaymentAddress");
let payment_addr = PaymentAddress::from(masp_payment_addr).pinned(pin);
let payment_addr = PaymentAddress::from(masp_payment_addr);
let alias = wallet
.insert_payment_addr(alias, payment_addr, alias_force)
.unwrap_or_else(|| {
Expand Down
206 changes: 4 additions & 202 deletions crates/apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

use std::collections::{BTreeMap, BTreeSet};
use std::io;
use std::str::FromStr;

use borsh::BorshDeserialize;
use data_encoding::HEXLOWER;
use masp_primitives::asset_type::AssetType;
use masp_primitives::merkle_tree::MerklePath;
use masp_primitives::sapling::{Node, ViewingKey};
use masp_primitives::sapling::Node;
use masp_primitives::transaction::components::I128Sum;
use masp_primitives::zip32::ExtendedFullViewingKey;
use namada::core::address::{Address, InternalAddress, MASP, MULTITOKEN};
use namada::core::collections::{HashMap, HashSet};
use namada::core::hash::Hash;
use namada::core::key::*;
use namada::core::masp::{BalanceOwner, ExtendedViewingKey, PaymentAddress};
use namada::core::masp::BalanceOwner;
use namada::core::storage::{BlockHeight, BlockResults, Epoch, Key, KeySeg};
use namada::core::token::MaspDigitPos;
use namada::governance::parameters::GovernanceParameters;
Expand All @@ -38,9 +37,7 @@ use namada::proof_of_stake::types::{
ValidatorState, ValidatorStateInfo, WeightedValidator,
};
use namada::{state as storage, token};
use namada_sdk::error::{
is_pinned_error, Error, PinnedBalanceError, QueryError,
};
use namada_sdk::error::QueryError;
use namada_sdk::masp::MaspTokenRewardData;
use namada_sdk::proof_of_stake::types::ValidatorMetaData;
use namada_sdk::queries::Client;
Expand All @@ -50,7 +47,7 @@ use namada_sdk::rpc::{
use namada_sdk::tendermint_rpc::endpoint::status;
use namada_sdk::tx::display_inner_resp;
use namada_sdk::wallet::AddressVpType;
use namada_sdk::{display, display_line, edisplay_line, error, prompt, Namada};
use namada_sdk::{display, display_line, edisplay_line, error, Namada};
use tokio::time::Instant;

use crate::cli::{self, args};
Expand Down Expand Up @@ -194,12 +191,7 @@ pub async fn query_balance(context: &impl Namada, args: args::QueryBalance) {
Some(BalanceOwner::Address(_owner)) => {
query_transparent_balance(context, args).await
}
Some(BalanceOwner::PaymentAddress(_owner)) => {
query_pinned_balance(context, args).await
}
None => {
// Print pinned balance
query_pinned_balance(context, args.clone()).await;
// Print shielded balance
query_shielded_balance(context, args.clone()).await;
// Then print transparent balance
Expand Down Expand Up @@ -301,196 +293,6 @@ pub async fn query_transparent_balance(
}
}

/// Query the token pinned balance(s)
pub async fn query_pinned_balance(
context: &impl Namada,
args: args::QueryBalance,
) {
// Map addresses to token names
let wallet = context.wallet().await;
let owners = if let Some(pa) = args.owner.and_then(|x| x.payment_address())
{
vec![pa]
} else {
wallet
.get_payment_addrs()
.into_values()
.filter(PaymentAddress::is_pinned)
.collect()
};
// Get the viewing keys with which to try note decryptions
let viewing_keys: Vec<ViewingKey> = wallet
.get_viewing_keys()
.values()
.map(|fvk| ExtendedFullViewingKey::from(*fvk).fvk.vk)
.collect();
let _ = context.shielded_mut().await.load().await;
// Precompute asset types to increase chances of success in decoding
let token_map =
query_tokens(context, args.token.as_ref(), None, args.show_ibc_tokens)
.await;
let tokens = token_map.values().collect();
let _ = context
.shielded_mut()
.await
.precompute_asset_types(context.client(), tokens)
.await;
// Print the token balances by payment address
for owner in owners {
let mut balance =
Err(Error::from(PinnedBalanceError::InvalidViewingKey));
// Find the viewing key that can recognize payments the current payment
// address
for vk in &viewing_keys {
balance = context
.shielded_mut()
.await
.compute_exchanged_pinned_balance(context, owner, vk)
.await;
if !is_pinned_error(&balance) {
break;
}
}
// If a suitable viewing key was not found, then demand it from the user
if is_pinned_error(&balance) {
let vk_str =
prompt!(context.io(), "Enter the viewing key for {}: ", owner)
.await;
let fvk = match ExtendedViewingKey::from_str(vk_str.trim()) {
Ok(fvk) => fvk,
_ => {
edisplay_line!(context.io(), "Invalid viewing key entered");
continue;
}
};
let vk = ExtendedFullViewingKey::from(fvk).fvk.vk;
// Use the given viewing key to decrypt pinned transaction data
balance = context
.shielded_mut()
.await
.compute_exchanged_pinned_balance(context, owner, &vk)
.await
}

// Now print out the received quantities according to CLI arguments
match (balance, args.token.as_ref()) {
(Err(Error::Pinned(PinnedBalanceError::InvalidViewingKey)), _) => {
display_line!(
context.io(),
"Supplied viewing key cannot decode transactions to given \
payment address."
)
}
(
Err(Error::Pinned(PinnedBalanceError::NoTransactionPinned)),
_,
) => {
display_line!(
context.io(),
"Payment address {} has not yet been consumed.",
owner
)
}
(Err(other), _) => {
display_line!(
context.io(),
"Error in Querying Pinned balance {}",
other
)
}
(Ok((balance, _undecoded, epoch)), Some(base_token)) => {
let tokens = query_tokens(
context,
Some(base_token),
None,
args.show_ibc_tokens,
)
.await;
for (token_alias, token) in &tokens {
let total_balance = balance
.0
.get(&token.clone())
.cloned()
.unwrap_or_default();

if total_balance.is_zero() {
display_line!(
context.io(),
"Payment address {} was consumed during epoch {}. \
Received no shielded {}",
owner,
epoch,
token_alias
);
} else {
let formatted = context
.format_amount(token, total_balance.into())
.await;
display_line!(
context.io(),
"Payment address {} was consumed during epoch {}. \
Received {} {}",
owner,
epoch,
formatted,
token_alias,
);
}
}
}
(Ok((balance, undecoded, epoch)), None) => {
let mut found_any = false;

for (token_addr, value) in balance.components() {
if !found_any {
display_line!(
context.io(),
"Payment address {} was consumed during epoch {}. \
Received:",
owner,
epoch
);
found_any = true;
}
let formatted = context
.format_amount(token_addr, (*value).into())
.await;
let token_alias =
lookup_token_alias(context, token_addr, &MASP).await;
display_line!(
context.io(),
" {}: {}",
token_alias,
formatted,
);
}
for (asset_type, value) in undecoded.components() {
if !found_any {
display_line!(
context.io(),
"Payment address {} was consumed during epoch {}. \
Received:",
owner,
epoch
);
found_any = true;
}
display_line!(context.io(), " {}: {}", asset_type, value,);
}
if !found_any {
display_line!(
context.io(),
"Payment address {} was consumed during epoch {}. \
Received no shielded assets.",
owner,
epoch
);
}
}
}
}
}

async fn print_balances(
context: &impl Namada,
balances: impl Iterator<Item = (storage::Key, token::Amount)>,
Expand Down
1 change: 0 additions & 1 deletion crates/benches/host_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ fn tx_section_signature_validation(c: &mut Criterion) {
target: defaults::bertha_address(),
token: address::testing::nam(),
amount: Amount::native_whole(500).native_denominated(),
key: None,
shielded: None,
};
let tx = shell.generate_tx(
Expand Down
1 change: 0 additions & 1 deletion crates/benches/native_vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ fn vp_multitoken(c: &mut Criterion) {
target: defaults::bertha_address(),
token: address::testing::nam(),
amount: Amount::native_whole(1000).native_denominated(),
key: None,
shielded: None,
},
None,
Expand Down
1 change: 0 additions & 1 deletion crates/benches/process_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ fn process_tx(c: &mut Criterion) {
target: defaults::bertha_address(),
token: address::testing::nam(),
amount: Amount::native_whole(1).native_denominated(),
key: None,
shielded: None,
},
None,
Expand Down
4 changes: 0 additions & 4 deletions crates/benches/vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ fn vp_implicit(c: &mut Criterion) {
target: defaults::bertha_address(),
token: address::testing::nam(),
amount: Amount::native_whole(500).native_denominated(),
key: None,
shielded: None,
},
None,
Expand All @@ -60,7 +59,6 @@ fn vp_implicit(c: &mut Criterion) {
target: Address::from(&implicit_account.to_public()),
token: address::testing::nam(),
amount: Amount::native_whole(1000).native_denominated(),
key: None,
shielded: None,
},
None,
Expand Down Expand Up @@ -189,7 +187,6 @@ fn vp_user(c: &mut Criterion) {
target: defaults::bertha_address(),
token: address::testing::nam(),
amount: Amount::native_whole(1000).native_denominated(),
key: None,
shielded: None,
},
None,
Expand All @@ -204,7 +201,6 @@ fn vp_user(c: &mut Criterion) {
target: defaults::validator_address(),
token: address::testing::nam(),
amount: Amount::native_whole(1000).native_denominated(),
key: None,
shielded: None,
},
None,
Expand Down
Loading
Loading