Skip to content

Commit

Permalink
Now hash the TransferTarget into Transaction transparent outputs.
Browse files Browse the repository at this point in the history
  • Loading branch information
murisi committed May 28, 2024
1 parent 6dc1612 commit e02fe43
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion crates/benches/native_vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ fn prepare_ibc_tx_and_ctx(bench_name: &str) -> (BenchShieldedCtx, BatchedTx) {
shielded_ctx.generate_shielded_action(
Amount::native_whole(10),
TransferSource::ExtendedSpendingKey(albert_spending_key),
TransferTarget::Address(defaults::bertha_address()),
defaults::bertha_address().to_string(),
)
}
_ => panic!("Unexpected bench test"),
Expand Down
14 changes: 10 additions & 4 deletions crates/core/src/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use namada_migrations::*;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};

use crate::address::{Address, DecodeError, HASH_HEX_LEN, MASP};
use crate::address::{Address, DecodeError, HASH_HEX_LEN, IBC, MASP};
use crate::impl_display_and_from_str_via_format;
use crate::storage::Epoch;
use crate::string_encoding::{
Expand Down Expand Up @@ -411,22 +411,27 @@ impl Display for TransferSource {
}

/// Represents a target for the funds of a transfer
#[derive(Debug, Clone)]
#[derive(Debug, Clone, BorshDeserialize, BorshSerialize, BorshDeserializer)]
pub enum TransferTarget {
/// A transfer going to a transparent address
Address(Address),
/// A transfer going to a shielded address
PaymentAddress(PaymentAddress),
/// A transfer going to an IBC address
Ibc(String),
}

impl TransferTarget {
/// Get the transparent address that this target would effectively go to
pub fn effective_address(&self) -> Address {
match self {
Self::Address(x) => x.clone(),
// An ExtendedSpendingKey for a source effectively means that
// assets will be drawn from the MASP
// A PaymentAddress for a target effectively means that assets will
// be sent to the MASP
Self::PaymentAddress(_) => MASP,
// An IBC signer address for a target effectively means that assets
// will be sent to the IBC internal address
Self::Ibc(_) => IBC,
}
}

Expand All @@ -452,6 +457,7 @@ impl Display for TransferTarget {
match self {
Self::Address(x) => x.fmt(f),
Self::PaymentAddress(address) => address.fmt(f),
Self::Ibc(x) => x.fmt(f),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/node/src/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,12 +1132,12 @@ impl BenchShieldedCtx {
self,
amount: Amount,
source: TransferSource,
target: TransferTarget,
target: String,
) -> (Self, BatchedTx) {
let (ctx, tx) = self.generate_masp_tx(
amount,
source.clone(),
TransferTarget::Address(Address::Internal(InternalAddress::Ibc)),
TransferTarget::Ibc(target.clone()),
);

let token = PrefixedCoin {
Expand Down Expand Up @@ -1165,7 +1165,7 @@ impl BenchShieldedCtx {
packet_data: PacketData {
token,
sender: source.effective_address().to_string().into(),
receiver: target.effective_address().to_string().into(),
receiver: target.into(),
memo: "".parse().unwrap(),
},
timeout_height_on_b: timeout_height,
Expand Down
9 changes: 1 addition & 8 deletions crates/sdk/src/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1762,14 +1762,7 @@ impl<U: ShieldedUtils + MaybeSend + MaybeSync> ShieldedContext<U> {
// the transparent target address into the shielded transaction so that
// it can be signed
let transparent_target_hash = if payment_address.is_none() {
let target_enc = target
.address()
.ok_or_else(|| {
Error::Other(
"target address should be transparent".to_string(),
)
})?
.serialize_to_vec();
let target_enc = target.serialize_to_vec();
Some(ripemd::Ripemd160::digest(sha2::Sha256::digest(
target_enc.as_ref(),
)))
Expand Down
2 changes: 1 addition & 1 deletion crates/sdk/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2512,7 +2512,7 @@ pub async fn build_ibc_transfer(
context,
&args.source,
// The token will be escrowed to IBC address
&TransferTarget::Address(Address::Internal(InternalAddress::Ibc)),
&TransferTarget::Ibc(args.receiver.clone()),
&args.token,
validated_amount,
!(args.tx.dry_run || args.tx.dry_run_wrapper),
Expand Down

0 comments on commit e02fe43

Please sign in to comment.