From 65cdd3e042e853e212a82fdebc6eb0376c8dc515 Mon Sep 17 00:00:00 2001 From: brentstone Date: Wed, 3 Jul 2024 17:04:07 -0700 Subject: [PATCH] fixup! Merge branch 'origin/grarco/masp-fee-payment' (#3393) --- crates/ibc/src/lib.rs | 2 ++ crates/namada/src/ledger/protocol/mod.rs | 14 +++++--- crates/sdk/src/masp.rs | 46 +++++++----------------- crates/tests/src/e2e/ibc_tests.rs | 1 + 4 files changed, 25 insertions(+), 38 deletions(-) diff --git a/crates/ibc/src/lib.rs b/crates/ibc/src/lib.rs index 045bce8e0d..5eaa00a1c2 100644 --- a/crates/ibc/src/lib.rs +++ b/crates/ibc/src/lib.rs @@ -338,6 +338,7 @@ pub fn decode_message(tx_data: &[u8]) -> Result { let msg = MsgTransfer { message, transfer: None, + fee_unshield: None, }; return Ok(IbcMessage::Transfer(msg)); } @@ -345,6 +346,7 @@ pub fn decode_message(tx_data: &[u8]) -> Result { let msg = MsgNftTransfer { message, transfer: None, + fee_unshield: None, }; return Ok(IbcMessage::NftTransfer(msg)); } diff --git a/crates/namada/src/ledger/protocol/mod.rs b/crates/namada/src/ledger/protocol/mod.rs index 6cec63b5ae..bb3af7c565 100644 --- a/crates/namada/src/ledger/protocol/mod.rs +++ b/crates/namada/src/ledger/protocol/mod.rs @@ -12,6 +12,7 @@ use namada_events::extend::{ }; use namada_events::EventLevel; use namada_gas::TxGasMeter; +use namada_parameters::get_gas_scale; use namada_state::TxWrites; use namada_token::event::{TokenEvent, TokenOperation, UserAccount}; use namada_token::utils::is_masp_transfer; @@ -487,10 +488,11 @@ where || (BatchResults::default(), None), |(batched_result, masp_section_ref)| { let mut batch = BatchResults::default(); - batch.0.insert( + batch.insert_inner_tx_result( // Ok to unwrap cause if we have a batched result it means // we've executed the first tx in the batch - tx.first_commitments().unwrap().get_hash(), + tx.wrapper_hash().as_ref(), + either::Right(tx.first_commitments().unwrap()), Ok(batched_result), ); (batch, Some(MaspTxRefs(vec![masp_section_ref]))) @@ -694,11 +696,13 @@ where .expect("Error reading the storage") .expect("Missing masp fee payment gas limit in storage") .min(tx_gas_meter.borrow().tx_gas_limit.into()); + let gas_scale = get_gas_scale(&**state).map_err(Error::StorageError)?; let mut gas_meter = TxGasMeter::new( - namada_gas::Gas::from_whole_units(max_gas_limit).ok_or_else(|| { - Error::GasError("Overflow in gas expansion".to_string()) - })?, + namada_gas::Gas::from_whole_units(max_gas_limit, gas_scale) + .ok_or_else(|| { + Error::GasError("Overflow in gas expansion".to_string()) + })?, ); gas_meter .copy_consumed_gas_from(&tx_gas_meter.borrow()) diff --git a/crates/sdk/src/masp.rs b/crates/sdk/src/masp.rs index aedebb1f28..03a2101764 100644 --- a/crates/sdk/src/masp.rs +++ b/crates/sdk/src/masp.rs @@ -62,6 +62,7 @@ use namada_token::{self as token, Denomination, MaspDigitPos}; use namada_tx::{IndexedTx, Tx}; use rand::rngs::StdRng; use rand_core::{CryptoRng, OsRng, RngCore, SeedableRng}; +use smooth_operator::checked; use thiserror::Error; use crate::error::{Error, QueryError}; @@ -1750,19 +1751,15 @@ impl ShieldedContext { // We add a dummy UTXO to our transaction, but only the source // of the parent Transfer object is used to // validate fund availability - let source_enc = source - .address() + let script = source + .t_addr_data() .ok_or_else(|| { Error::Other( "source address should be transparent".to_string(), ) })? - .serialize_to_vec(); + .taddress(); - let hash = ripemd::Ripemd160::digest(sha2::Sha256::digest( - source_enc.as_ref(), - )); - let script = TransparentAddress(hash.into()); for (digit, asset_type) in MaspDigitPos::iter().zip(asset_types.iter()) { @@ -1809,24 +1806,7 @@ impl ShieldedContext { .await; let payment_address = target.payment_address(); - // If we are sending to a transparent output, then we will need to - // embed 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(); - Some(ripemd::Ripemd160::digest(sha2::Sha256::digest( - target_enc.as_ref(), - ))) - } else { - None - }; + // This indicates how many more assets need to be sent to the // receiver in order to satisfy the requested transfer // amount. @@ -1876,17 +1856,11 @@ impl ShieldedContext { error: builder::Error::SaplingBuild(e), data: None, })?; - } else { + } else if let Some(t_addr_data) = target.t_addr_data() { // If there is a transparent output - let hash = transparent_target_hash - .expect( - "transparent target hash should have been \ - computed already", - ) - .into(); builder .add_transparent_output( - &TransparentAddress(hash), + &t_addr_data.taddress(), *asset_type, contr, ) @@ -1894,6 +1868,12 @@ impl ShieldedContext { error: builder::Error::TransparentBuild(e), data: None, })?; + } else { + return Result::Err(TransferErr::from(Error::Other( + "transaction target must be a payment address or \ + Namada address or IBC address" + .to_string(), + ))); } // Lower what is required of the remaining contribution *rem_amount -= contr; diff --git a/crates/tests/src/e2e/ibc_tests.rs b/crates/tests/src/e2e/ibc_tests.rs index 9e27075409..39cd3fbd91 100644 --- a/crates/tests/src/e2e/ibc_tests.rs +++ b/crates/tests/src/e2e/ibc_tests.rs @@ -300,6 +300,7 @@ fn run_ledger_ibc_with_hermes() -> Result<()> { NAM, 10_000, ALBERT_KEY, + false, )?; shielded_sync(&test_a, AA_VIEWING_KEY)?; // Shieded transfer from Chain A to Chain B