diff --git a/.changelog/unreleased/bug-fixes/3463-non-malleable-masp-witness-data2.md b/.changelog/unreleased/bug-fixes/3463-non-malleable-masp-witness-data2.md new file mode 100644 index 0000000000..e206354cba --- /dev/null +++ b/.changelog/unreleased/bug-fixes/3463-non-malleable-masp-witness-data2.md @@ -0,0 +1,2 @@ +- Fixed MASP witness data malleability in the Tx + ([\#3463](https://github.com/anoma/namada/pull/3463)) \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index c68138142c..68a9f64c39 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -972,9 +972,9 @@ dependencies = [ [[package]] name = "ciborium" -version = "0.2.2" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" +checksum = "effd91f6c78e5a4ace8a5d3c0b6bfaec9e2baaef55f3efc00e45fb2e477ee926" dependencies = [ "ciborium-io", "ciborium-ll", @@ -983,18 +983,18 @@ dependencies = [ [[package]] name = "ciborium-io" -version = "0.2.2" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" +checksum = "cdf919175532b369853f5d5e20b26b43112613fd6fe7aee757e35f7a44642656" [[package]] name = "ciborium-ll" -version = "0.2.2" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" +checksum = "defaa24ecc093c77630e6c15e17c51f5e187bf35ee514f4e2d67baaa96dae22b" dependencies = [ "ciborium-io", - "half 2.4.1", + "half", ] [[package]] @@ -1030,18 +1030,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.8" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84b3edb18336f4df585bc9aa31dd99c036dfa5dc5e9a2939a722a188f3a8970d" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.8" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1c09dd5ada6c6c78075d6fd0da3f90d8080651e2d6cc8eb2f1aaa4034ced708" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" dependencies = [ "anstream", "anstyle", @@ -1051,18 +1051,18 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.5.7" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d598e88f6874d4b888ed40c71efbcbf4076f1dfbae128a08a8c9e45f710605d" +checksum = "dd79504325bf38b10165b02e89b4347300f855f273c4cb30c4a3209e6583275e" dependencies = [ "clap", ] [[package]] name = "clap_complete_nushell" -version = "4.5.2" +version = "4.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1accf1b463dee0d3ab2be72591dccdab8bef314958340447c882c4c72acfe2a3" +checksum = "80d0e48e026ce7df2040239117d25e4e79714907420c70294a5ce4b6bbe6a7b6" dependencies = [ "clap", "clap_complete", @@ -1070,9 +1070,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "clru" @@ -2104,9 +2104,9 @@ dependencies = [ [[package]] name = "either" -version = "1.13.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" [[package]] name = "elliptic-curve" @@ -3019,16 +3019,6 @@ version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" -[[package]] -name = "half" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" -dependencies = [ - "cfg-if", - "crunchy", -] - [[package]] name = "hash32" version = "0.2.1" @@ -4073,13 +4063,13 @@ checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "is-terminal" -version = "0.4.12" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi", - "libc", - "windows-sys 0.52.0", + "rustix", + "windows-sys 0.48.0", ] [[package]] @@ -4461,7 +4451,7 @@ dependencies = [ [[package]] name = "masp_note_encryption" version = "1.0.0" -source = "git+https://github.com/anoma/masp?rev=71b36beba21e35f8611f3ba6910ed5b78ec11af1#71b36beba21e35f8611f3ba6910ed5b78ec11af1" +source = "git+https://github.com/anoma/masp?rev=8d83b172698098fba393006016072bc201ed9ab7#8d83b172698098fba393006016072bc201ed9ab7" dependencies = [ "borsh 1.2.1", "chacha20", @@ -4474,7 +4464,7 @@ dependencies = [ [[package]] name = "masp_primitives" version = "1.0.0" -source = "git+https://github.com/anoma/masp?rev=71b36beba21e35f8611f3ba6910ed5b78ec11af1#71b36beba21e35f8611f3ba6910ed5b78ec11af1" +source = "git+https://github.com/anoma/masp?rev=8d83b172698098fba393006016072bc201ed9ab7#8d83b172698098fba393006016072bc201ed9ab7" dependencies = [ "aes", "bip0039", @@ -4506,7 +4496,7 @@ dependencies = [ [[package]] name = "masp_proofs" version = "1.0.0" -source = "git+https://github.com/anoma/masp?rev=71b36beba21e35f8611f3ba6910ed5b78ec11af1#71b36beba21e35f8611f3ba6910ed5b78ec11af1" +source = "git+https://github.com/anoma/masp?rev=8d83b172698098fba393006016072bc201ed9ab7#8d83b172698098fba393006016072bc201ed9ab7" dependencies = [ "bellman", "blake2b_simd", @@ -6126,9 +6116,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.5" +version = "2.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae9cee2a55a544be8b89dc6848072af97a20f2422603c10865be2a42b580fff5" +checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8" dependencies = [ "memchr", "thiserror", @@ -6137,9 +6127,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.7.5" +version = "2.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81d78524685f5ef2a3b3bd1cafbc9fcabb036253d9b1463e726a91cd16e2dfc2" +checksum = "26293c9193fbca7b1a3bf9b79dc1e388e927e6cacaa78b4a3ab705a1d3d41459" dependencies = [ "pest", "pest_generator", @@ -6147,9 +6137,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.5" +version = "2.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68bd1206e71118b5356dae5ddc61c8b11e28b09ef6a31acbd15ea48a28e0c227" +checksum = "3ec22af7d3fb470a85dd2ca96b7c577a1eb4ef6f1683a9fe9a8c16e136c04687" dependencies = [ "pest", "pest_meta", @@ -6160,9 +6150,9 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.7.5" +version = "2.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c747191d4ad9e4a4ab9c8798f1e82a39affe7ef9648390b7e5548d18e099de6" +checksum = "d7a240022f37c361ec1878d646fc5b7d7c4d28d5946e1a80ad5a7a4f4ca0bdcd" dependencies = [ "once_cell", "pest", @@ -6245,9 +6235,9 @@ checksum = "14e6ab3f592e6fb464fc9712d8d6e6912de6473954635fd76a589d832cffcbb0" [[package]] name = "plotters" -version = "0.3.6" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a15b6eccb8484002195a3e44fe65a4ce8e93a625797a063735536fd59cb01cf3" +checksum = "d2c224ba00d7cadd4d5c660deaf2098e5e80e07846537c51f9cfa4be50c1fd45" dependencies = [ "num-traits 0.2.17", "plotters-backend", @@ -6258,15 +6248,15 @@ dependencies = [ [[package]] name = "plotters-backend" -version = "0.3.6" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "414cec62c6634ae900ea1c56128dfe87cf63e7caece0852ec76aba307cebadb7" +checksum = "9e76628b4d3a7581389a35d5b6e2139607ad7c75b17aed325f210aa91f4a9609" [[package]] name = "plotters-svg" -version = "0.3.6" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81b30686a7d9c3e010b84284bdd26a29f2138574f52f5eb6f794fc0ad924e705" +checksum = "38f6d39893cca0701371e3c27294f09797214b86f1fb951b89ade8ec04e2abab" dependencies = [ "plotters-backend", ] @@ -7349,9 +7339,9 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.202" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] @@ -7400,15 +7390,15 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" dependencies = [ - "half 1.8.2", + "half", "serde", ] [[package]] name = "serde_derive" -version = "1.0.202" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", @@ -9131,9 +9121,9 @@ dependencies = [ [[package]] name = "wasmer" -version = "4.3.1" +version = "4.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce4a267a570e121c9375136adefa2c48810273907de9c6817bc19db4d6144bc" +checksum = "b1852ee143a2d8143265bfee017c43bf690702d6c2b45a763a2f13e669f5b7ec" dependencies = [ "bytes", "cfg-if", @@ -9160,9 +9150,9 @@ dependencies = [ [[package]] name = "wasmer-cache" -version = "4.3.1" +version = "4.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67a40804bcc2567f112003182fc5edc29584da5199c4a1f5a8d6a6e4b65feff0" +checksum = "092ca4da29a7320b99c9b6660dfbde055f4db0a71c1273860272c213b2f7e019" dependencies = [ "blake3", "hex", @@ -9172,9 +9162,9 @@ dependencies = [ [[package]] name = "wasmer-compiler" -version = "4.3.1" +version = "4.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9c23098e86ef1038155684fe50f0c1079a0e2a2e70f115b789df17e6ba98d20" +checksum = "6b4f157d715f3bb60c2c9d7b9e48299a30e9209f87f4484f79f9cd586b40b6ee" dependencies = [ "backtrace", "bytes", @@ -9200,9 +9190,9 @@ dependencies = [ [[package]] name = "wasmer-compiler-cranelift" -version = "4.3.1" +version = "4.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95287b79973ad5f485215733ef9f0d4bb951a6b7e655585d2bd3d4a4ba1253c9" +checksum = "eb457e66b77ca2188fbbd6c2056ec6e8ccb4bddee73e60ba9d39733d7b2e8068" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -9219,9 +9209,9 @@ dependencies = [ [[package]] name = "wasmer-compiler-singlepass" -version = "4.3.1" +version = "4.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00d78d59be3ce78ad859e176b88f0d5bec0120ece0684922d7c5da1289e251b1" +checksum = "0a3196b2a87d5c6692021ece7ad1cf7fe43b7f1669c3aba1b8ccfcebe660070c" dependencies = [ "byteorder", "dynasm", @@ -9260,9 +9250,9 @@ dependencies = [ [[package]] name = "wasmer-derive" -version = "4.3.1" +version = "4.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48f36aeeecb655f15fdd358bdf6e4cec27df181468fa4226084157e8462bd5e" +checksum = "32cd5732ff64370e98986f9753cce13b91cc9d3c4b649e31b0d08d5db69164ea" dependencies = [ "proc-macro-error", "proc-macro2", @@ -9272,9 +9262,9 @@ dependencies = [ [[package]] name = "wasmer-types" -version = "4.3.1" +version = "4.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83cb97b6b20084757a2a8d548dc0d4179c3fe9e2d711740423a1e6aa3f8b9091" +checksum = "c890fd0dbda40df03977b899d1ad7113deba3c225f2cc7b88deb7633044d3e07" dependencies = [ "bytecheck", "enum-iterator", @@ -9293,9 +9283,9 @@ dependencies = [ [[package]] name = "wasmer-vm" -version = "4.3.1" +version = "4.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc1e19d986844b17b927ec8b0c7f3da6a7a2c2cb3b0f8ca5d4cb1a1f71bfb124" +checksum = "5e0dc60ab800cf0bd44e2d35d88422d256d2470b00c72778f91bfb826c42dbd0" dependencies = [ "backtrace", "cc", @@ -9795,9 +9785,9 @@ dependencies = [ [[package]] name = "yaml-rust2" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "498f4d102a79ea1c9d4dd27573c0fc96ad74c023e8da38484e47883076da25fb" +checksum = "8902160c4e6f2fb145dbe9d6760a75e3c9522d8bf796ed7047c85919ac7115f8" dependencies = [ "arraydeque", "encoding_rs", diff --git a/Cargo.toml b/Cargo.toml index 703cb91e0f..0e3d84a923 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -127,8 +127,8 @@ libc = "0.2.97" libloading = "0.7.2" linkme = "0.3.24" # branch = "main" -masp_primitives = { git = "https://github.com/anoma/masp", rev = "71b36beba21e35f8611f3ba6910ed5b78ec11af1" } -masp_proofs = { git = "https://github.com/anoma/masp", rev = "71b36beba21e35f8611f3ba6910ed5b78ec11af1", default-features = false, features = ["local-prover"] } +masp_primitives = { git = "https://github.com/anoma/masp", rev = "8d83b172698098fba393006016072bc201ed9ab7" } +masp_proofs = { git = "https://github.com/anoma/masp", rev = "8d83b172698098fba393006016072bc201ed9ab7", default-features = false, features = ["local-prover"] } num256 = "0.3.5" num_cpus = "1.13.0" num-derive = "0.4" diff --git a/crates/core/src/masp.rs b/crates/core/src/masp.rs index 562a6d0268..a3b6736b05 100644 --- a/crates/core/src/masp.rs +++ b/crates/core/src/masp.rs @@ -13,11 +13,10 @@ use namada_macros::BorshDeserializer; #[cfg(feature = "migrations")] use namada_migrations::*; use ripemd::Digest as RipemdDigest; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; use sha2::{Digest, Sha256}; use crate::address::{Address, DecodeError, HASH_HEX_LEN, IBC, MASP}; -use crate::hash::Hash; use crate::impl_display_and_from_str_via_format; use crate::storage::Epoch; use crate::string_encoding::{ @@ -26,6 +25,62 @@ use crate::string_encoding::{ }; use crate::token::{Denomination, MaspDigitPos}; +/// Serialize the given TxId +pub fn serialize_txid( + txid: &masp_primitives::transaction::TxId, + s: S, +) -> Result +where + S: Serializer, +{ + s.serialize_bytes(txid.as_ref()) +} + +/// Deserialize the given TxId +pub fn deserialize_txid<'de, D>( + deserializer: D, +) -> Result +where + D: Deserializer<'de>, +{ + Ok(masp_primitives::transaction::TxId::from_bytes( + Deserialize::deserialize(deserializer)?, + )) +} + +/// Wrapper for masp_primitive's TxId +#[derive( + Serialize, + Deserialize, + Clone, + BorshSerialize, + BorshDeserialize, + BorshSchema, + Debug, + Eq, + PartialEq, + Copy, + Ord, + PartialOrd, + Hash, +)] +pub struct MaspTxId( + #[serde( + serialize_with = "serialize_txid", + deserialize_with = "deserialize_txid" + )] + masp_primitives::transaction::TxId, +); + +impl From for MaspTxId { + fn from(txid: masp_primitives::transaction::TxId) -> Self { + Self(txid) + } +} + +/// Wrapper for masp_primitive's TxId +pub type TxId = MaspTxId; + /// Wrapper type around `Epoch` for type safe operations involving the masp /// epoch #[derive( @@ -699,7 +754,7 @@ impl FromStr for MaspValue { /// The masp transactions' references of a given batch #[derive(Default, Clone, Serialize, Deserialize)] -pub struct MaspTxRefs(pub Vec); +pub struct MaspTxRefs(pub Vec); impl Display for MaspTxRefs { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { diff --git a/crates/light_sdk/src/transaction/transfer.rs b/crates/light_sdk/src/transaction/transfer.rs index 15c61b2a88..167db94ce3 100644 --- a/crates/light_sdk/src/transaction/transfer.rs +++ b/crates/light_sdk/src/transaction/transfer.rs @@ -1,6 +1,7 @@ use namada_sdk::address::Address; use namada_sdk::hash::Hash; use namada_sdk::key::common; +use namada_sdk::masp::TxId; use namada_sdk::token::transaction::Transaction; pub use namada_sdk::token::{DenominatedAmount, Transfer}; use namada_sdk::tx::data::GasLimit; @@ -25,7 +26,7 @@ impl TransferBuilder { /// Build a shielded transfer transaction from the given parameters pub fn shielded( - shielded_section_hash: Hash, + shielded_section_hash: TxId, transaction: Transaction, args: GlobalArgs, ) -> Self { diff --git a/crates/namada/src/ledger/native_vp/masp.rs b/crates/namada/src/ledger/native_vp/masp.rs index 033b6cdeca..f116ca0057 100644 --- a/crates/namada/src/ledger/native_vp/masp.rs +++ b/crates/namada/src/ledger/native_vp/masp.rs @@ -669,8 +669,8 @@ where })?; let shielded_tx = tx_data .tx - .get_section(&masp_section_ref) - .and_then(|section| section.masp_tx()) + .get_masp_section(&masp_section_ref) + .cloned() .ok_or_else(|| { native_vp::Error::new_const( "Missing MASP section in transaction", diff --git a/crates/namada/src/ledger/protocol/mod.rs b/crates/namada/src/ledger/protocol/mod.rs index bb3af7c565..b475969d58 100644 --- a/crates/namada/src/ledger/protocol/mod.rs +++ b/crates/namada/src/ledger/protocol/mod.rs @@ -6,7 +6,7 @@ use std::fmt::Debug; use eyre::{eyre, WrapErr}; use namada_core::booleans::BoolResultUnitExt; use namada_core::hash::Hash; -use namada_core::masp::MaspTxRefs; +use namada_core::masp::{MaspTxRefs, TxId}; use namada_events::extend::{ ComposeEvent, Height as HeightAttr, TxHash as TxHashAttr, }; @@ -521,7 +521,7 @@ pub fn transfer_fee( tx: &Tx, wrapper: &WrapperTx, tx_index: &TxIndex, -) -> Result> +) -> Result> where S: State + StorageRead @@ -674,7 +674,7 @@ fn try_masp_fee_payment( }: &mut ShellParams<'_, S, D, H, CA>, tx: &Tx, tx_index: &TxIndex, -) -> Result> +) -> Result> where S: State + StorageRead @@ -804,7 +804,7 @@ pub fn check_fees( shell_params: &mut ShellParams<'_, S, D, H, CA>, tx: &Tx, wrapper: &WrapperTx, -) -> Result> +) -> Result> where S: State + StorageRead diff --git a/crates/node/src/bench_utils.rs b/crates/node/src/bench_utils.rs index 70a9ecf6b0..d4f9bf6334 100644 --- a/crates/node/src/bench_utils.rs +++ b/crates/node/src/bench_utils.rs @@ -110,7 +110,6 @@ use namada_sdk::wallet::Wallet; use namada_sdk::{Namada, NamadaImpl}; use namada_test_utils::tx_data::TxWriteData; use rand_core::OsRng; -use sha2::{Digest, Sha256}; use tempfile::TempDir; use crate::config; @@ -948,8 +947,10 @@ impl Client for BenchShell { tx.sections .iter() .find_map(|section| { - if let Section::MaspTx(_) = section { - Some(section.get_hash()) + if let Section::MaspTx(transaction) = + section + { + Some(transaction.txid().into()) } else { None } @@ -1118,13 +1119,7 @@ impl BenchShieldedCtx { ) .expect("MASP must have shielded part"); - let mut hasher = Sha256::new(); - let shielded_section_hash = namada::core::hash::Hash( - Section::MaspTx(shielded.clone()) - .hash(&mut hasher) - .finalize_reset() - .into(), - ); + let shielded_section_hash = shielded.txid().into(); let tx = if source.effective_address() == MASP && target.effective_address() == MASP { @@ -1244,10 +1239,9 @@ impl BenchShieldedCtx { }; let masp_tx = tx .tx - .get_section(&transfer.shielded_section_hash.unwrap()) + .get_masp_section(&transfer.shielded_section_hash.unwrap()) .unwrap() - .masp_tx() - .unwrap(); + .clone(); let msg = MsgTransfer { message: msg, transfer: Some(transfer), diff --git a/crates/sdk/src/masp.rs b/crates/sdk/src/masp.rs index 03a2101764..f5380173d2 100644 --- a/crates/sdk/src/masp.rs +++ b/crates/sdk/src/masp.rs @@ -41,7 +41,7 @@ use namada_core::collections::{HashMap, HashSet}; use namada_core::dec::Dec; pub use namada_core::masp::{ encode_asset_type, AssetData, BalanceOwner, ExtendedViewingKey, - PaymentAddress, TAddrData, TransferSource, TransferTarget, + PaymentAddress, TAddrData, TransferSource, TransferTarget, TxId, }; use namada_core::masp::{MaspEpoch, MaspTxRefs}; use namada_core::storage::{BlockHeight, TxIndex}; @@ -687,14 +687,11 @@ impl ShieldedContext { .0 .iter() .try_fold(vec![], |mut acc, hash| { - match tx - .get_section(hash) - .and_then(|section| section.masp_tx()) - .ok_or_else(|| { - Error::Other( - "Missing expected masp transaction".to_string(), - ) - }) { + match tx.get_masp_section(hash).cloned().ok_or_else(|| { + Error::Other( + "Missing expected masp transaction".to_string(), + ) + }) { Ok(transaction) => { acc.push(transaction); Ok(acc) diff --git a/crates/sdk/src/tx.rs b/crates/sdk/src/tx.rs index 103a0f8085..2fb043bfac 100644 --- a/crates/sdk/src/tx.rs +++ b/crates/sdk/src/tx.rs @@ -3721,8 +3721,7 @@ pub async fn gen_ibc_shielding_transfer( .map_err(|err| TxSubmitError::MaspError(err.to_string()))?; if let Some(shielded_transfer) = shielded_transfer { - let masp_tx_hash = - Section::MaspTx(shielded_transfer.masp_tx.clone()).get_hash(); + let masp_tx_hash = shielded_transfer.masp_tx.txid().into(); let transfer = token::Transfer::masp(masp_tx_hash); Ok(Some((transfer, shielded_transfer.masp_tx))) } else { diff --git a/crates/token/src/lib.rs b/crates/token/src/lib.rs index d5ae2bc54e..6ad9b323bb 100644 --- a/crates/token/src/lib.rs +++ b/crates/token/src/lib.rs @@ -19,7 +19,6 @@ )] use namada_core::borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use namada_core::hash::Hash; use namada_macros::BorshDeserializer; pub use namada_shielded_token::*; pub use namada_trans_token::*; @@ -34,6 +33,7 @@ pub mod storage_key { use std::collections::BTreeMap; use namada_core::address::Address; +use namada_core::masp::TxId; use namada_events::EmitEvents; use namada_storage::{Result, StorageRead, StorageWrite}; @@ -114,12 +114,12 @@ pub struct Transfer { /// Targets of this transfer pub targets: BTreeMap, /// Hash of tx section that contains the MASP transaction - pub shielded_section_hash: Option, + pub shielded_section_hash: Option, } impl Transfer { /// Create a MASP transaction - pub fn masp(hash: Hash) -> Self { + pub fn masp(hash: TxId) -> Self { Self { shielded_section_hash: Some(hash), ..Self::default() diff --git a/crates/tx/src/action.rs b/crates/tx/src/action.rs index 6748e181aa..f8826b47c6 100644 --- a/crates/tx/src/action.rs +++ b/crates/tx/src/action.rs @@ -8,7 +8,7 @@ use std::fmt; use namada_core::address::Address; use namada_core::borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::hash::Hash; +use namada_core::masp::TxId; use namada_core::storage::KeySeg; use namada_core::{address, storage}; @@ -67,7 +67,7 @@ pub enum PgfAction { #[derive(Clone, Debug, BorshDeserialize, BorshSerialize)] pub struct MaspAction { /// The hash of the masp [`crate::types::Section`] - pub masp_section_ref: Hash, + pub masp_section_ref: TxId, } /// Read actions from temporary storage @@ -123,7 +123,7 @@ fn storage_key() -> storage::Key { /// first one pub fn get_masp_section_ref( reader: &T, -) -> Result, ::Err> { +) -> Result, ::Err> { Ok(reader.read_actions()?.into_iter().find_map(|action| { // In case of multiple masp actions we get the first one if let Action::Masp(MaspAction { masp_section_ref }) = action { diff --git a/crates/tx/src/types.rs b/crates/tx/src/types.rs index 5d6f6f4229..a8b3198006 100644 --- a/crates/tx/src/types.rs +++ b/crates/tx/src/types.rs @@ -18,7 +18,7 @@ use namada_core::borsh::{ use namada_core::chain::ChainId; use namada_core::collections::{HashMap, HashSet}; use namada_core::key::*; -use namada_core::masp::AssetData; +use namada_core::masp::{AssetData, TxId}; use namada_core::sign::SignatureIndex; use namada_core::storage::{BlockHeight, TxIndex}; use namada_core::time::DateTimeUtc; @@ -719,7 +719,7 @@ impl From for Vec { )] pub struct MaspBuilder { /// The MASP transaction that this section witnesses - pub target: namada_core::hash::Hash, + pub target: TxId, /// The decoded set of asset types used by the transaction. Useful for /// offline wallets trying to display AssetTypes. pub asset_types: HashSet, @@ -802,7 +802,7 @@ impl Section { Self::Authorization(signature) => signature.hash(hasher), Self::MaspBuilder(mb) => mb.hash(hasher), Self::MaspTx(tx) => { - hasher.update(tx.txid().as_ref()); + hasher.update(tx.serialize_to_vec()); hasher } Self::Header(header) => header.hash(hasher), @@ -1191,6 +1191,18 @@ impl Tx { None } + /// Get the transaction section with the given hash + pub fn get_masp_section(&self, hash: &TxId) -> Option<&Transaction> { + for section in &self.sections { + if let Section::MaspTx(masp) = section { + if TxId::from(masp.txid()) == *hash { + return Some(masp); + } + } + } + None + } + /// Set the last transaction memo hash stored in the header pub fn set_memo_sechash(&mut self, hash: namada_core::hash::Hash) { let item = match self.header.batch.pop() { @@ -1547,9 +1559,10 @@ impl Tx { pub fn add_masp_tx_section( &mut self, tx: Transaction, - ) -> (&mut Self, namada_core::hash::Hash) { - let sechash = self.add_section(Section::MaspTx(tx)).get_hash(); - (self, sechash) + ) -> (&mut Self, TxId) { + let txid = tx.txid(); + self.add_section(Section::MaspTx(tx)); + (self, txid.into()) } /// Add a masp builder section to the tx builder diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index aa00928539..211d4b866f 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -3518,7 +3518,7 @@ dependencies = [ [[package]] name = "masp_note_encryption" version = "1.0.0" -source = "git+https://github.com/anoma/masp?rev=71b36beba21e35f8611f3ba6910ed5b78ec11af1#71b36beba21e35f8611f3ba6910ed5b78ec11af1" +source = "git+https://github.com/anoma/masp?rev=8d83b172698098fba393006016072bc201ed9ab7#8d83b172698098fba393006016072bc201ed9ab7" dependencies = [ "borsh 1.4.0", "chacha20", @@ -3531,7 +3531,7 @@ dependencies = [ [[package]] name = "masp_primitives" version = "1.0.0" -source = "git+https://github.com/anoma/masp?rev=71b36beba21e35f8611f3ba6910ed5b78ec11af1#71b36beba21e35f8611f3ba6910ed5b78ec11af1" +source = "git+https://github.com/anoma/masp?rev=8d83b172698098fba393006016072bc201ed9ab7#8d83b172698098fba393006016072bc201ed9ab7" dependencies = [ "aes", "bip0039", @@ -3563,7 +3563,7 @@ dependencies = [ [[package]] name = "masp_proofs" version = "1.0.0" -source = "git+https://github.com/anoma/masp?rev=71b36beba21e35f8611f3ba6910ed5b78ec11af1#71b36beba21e35f8611f3ba6910ed5b78ec11af1" +source = "git+https://github.com/anoma/masp?rev=8d83b172698098fba393006016072bc201ed9ab7#8d83b172698098fba393006016072bc201ed9ab7" dependencies = [ "bellman", "blake2b_simd", diff --git a/wasm/checksums.json b/wasm/checksums.json index fbfd1e13cc..261ab6524a 100644 --- a/wasm/checksums.json +++ b/wasm/checksums.json @@ -1,26 +1,26 @@ { - "tx_become_validator.wasm": "tx_become_validator.a80653555d1577d5f5b0bbd3abe7176f5343cf81058d034075eada183a85a3ed.wasm", - "tx_bond.wasm": "tx_bond.59f55583bde3359cbb60540dd467a4d37e4635129ee64a4152c4d4b33d1c0333.wasm", - "tx_bridge_pool.wasm": "tx_bridge_pool.993113b5125da5858bf797e55dd4f7acbcf38d6ecc62082df2d71bb9209298b8.wasm", - "tx_change_consensus_key.wasm": "tx_change_consensus_key.4ca0a5d076a0c658f387ba76041508ed6692f2a449de0db3764620bdd2c40203.wasm", - "tx_change_validator_commission.wasm": "tx_change_validator_commission.c8d77e51ebd42f62a7fee89b3d2590b7e6229fe986c0eea5da460ccb5401e84b.wasm", - "tx_change_validator_metadata.wasm": "tx_change_validator_metadata.870f234be24dd3dd0ec7f16214239be85b0792f60e5f96fcf2ccba2f66420882.wasm", - "tx_claim_rewards.wasm": "tx_claim_rewards.43e030a52a4eef4e22c220fa67e538e7910ef8b8cd24a9c27279e4edebe7ad49.wasm", - "tx_deactivate_validator.wasm": "tx_deactivate_validator.8a4e61578deac8834403ae423e5cba6b8e944a80e5981b203940226d148540b8.wasm", - "tx_ibc.wasm": "tx_ibc.1098802721088e443be99fd7ead5e68eb949714c2f437d7b5406aa50a1f4f462.wasm", - "tx_init_account.wasm": "tx_init_account.3e9e8333c2d15f34dc2ff7a7a7daea57e79bfd1047f10361d58f78c6ed88d98f.wasm", - "tx_init_proposal.wasm": "tx_init_proposal.f31712a801e1de6d54ff0c4a3da3b642e4980e1ab24cb98a83bcae780b759c22.wasm", - "tx_reactivate_validator.wasm": "tx_reactivate_validator.218186c654993c3253b50b00d0df154a490a59d0d4463166064ea4a69fcf0190.wasm", - "tx_redelegate.wasm": "tx_redelegate.43111c157b245de760d3435ae1b31ed539c268980268a53ed6901593e08bf27e.wasm", - "tx_resign_steward.wasm": "tx_resign_steward.c2b2b3146769eba76d3ab5793ff3e912cb2d37c568a2682cf42c13b4b5fe625d.wasm", - "tx_reveal_pk.wasm": "tx_reveal_pk.49b4b3e58f35dc4eae8ec38d5736804ac2fd1070f84daf0372b107a6207bcb31.wasm", - "tx_transfer.wasm": "tx_transfer.49da99c397400ea51cd915874946e40c5c2071a980e25739910339214529a68f.wasm", - "tx_unbond.wasm": "tx_unbond.0b989b13181e113aadebaacdbd1c335dd123bf1eefdf15111aad785dcadb1a7e.wasm", - "tx_unjail_validator.wasm": "tx_unjail_validator.ba8c4ecf9b43eb0bc6a1e6d81c9e50d01c219e3a25ecb73b80d924b65197ae18.wasm", - "tx_update_account.wasm": "tx_update_account.9c09b59ff07d75a0b904f06d041e042be1b27f5c30305e67a28f51e8f14ba1fb.wasm", - "tx_update_steward_commission.wasm": "tx_update_steward_commission.88ee68464f19858353a564ba19d1c26484eb6715010545f0615380dc1c920f93.wasm", - "tx_vote_proposal.wasm": "tx_vote_proposal.f62106e01f608c66c9db2c3c3b07e606e108593fda32f2acfb65ee4e51c37209.wasm", - "tx_withdraw.wasm": "tx_withdraw.c8c18e6e5efe3dd2bdedf228cd960ff5bda028658b0fe20e4926062c2a7b3957.wasm", - "vp_implicit.wasm": "vp_implicit.8dfe9c6592bd3eccd4145cf29d21957bf05b5ecd8d617343a8b33eebfd68b005.wasm", - "vp_user.wasm": "vp_user.482170efc60dfbdf4114fa87e4fbf67236b19588e213a5f5179184ca74d2a623.wasm" + "tx_become_validator.wasm": "tx_become_validator.bc6bff5b4d334792d1e195a819a721ae8784cd93cada0435f74e827ebb093e32.wasm", + "tx_bond.wasm": "tx_bond.eaa80b7a8241431427b833129b869e77d9acf54d7acd10ce98d4dc1664278eea.wasm", + "tx_bridge_pool.wasm": "tx_bridge_pool.05a5c52e15e45e1aa2ee667ccebde0ba9b68566dafa2f1ad4f366d9e4d52482b.wasm", + "tx_change_consensus_key.wasm": "tx_change_consensus_key.54aead512bccce8408bcd91857f7be2348009e6699e18800f5a35a222203816b.wasm", + "tx_change_validator_commission.wasm": "tx_change_validator_commission.70db3f6be1c7ab92ad62c43c76a30a7b761d54354ab78c408d973c309c651c43.wasm", + "tx_change_validator_metadata.wasm": "tx_change_validator_metadata.538e2e4d5427322508ff9838fcebedfa43d24338a22df16e70deed23f99edd78.wasm", + "tx_claim_rewards.wasm": "tx_claim_rewards.08c5dd61fa52c42299d1a28f91d0df63a0d1e8cdc71be456f6ea3836776501a7.wasm", + "tx_deactivate_validator.wasm": "tx_deactivate_validator.cbc394cfc3db51f63a5c79a9115207b8fcf888f4b7e6b207d0146b975b135f79.wasm", + "tx_ibc.wasm": "tx_ibc.a2f25d6049a0222bd498784807b51ef0633b32b33df688e3c9ad22f28ebc5088.wasm", + "tx_init_account.wasm": "tx_init_account.dfadff42fbec37a467ac005c30dfe41f07e053fdfd8327c66263a597dc371dae.wasm", + "tx_init_proposal.wasm": "tx_init_proposal.3035b59994080a77d4d1f3d33c9470d04d1e10947c611831fe634d64b2d5f558.wasm", + "tx_reactivate_validator.wasm": "tx_reactivate_validator.d6a9389fc30cb060206a0b057e7cca380a8f584fbabeef4295e11f78f16407bd.wasm", + "tx_redelegate.wasm": "tx_redelegate.98df7cbb9dba1c337fbbcba189bf86fd4ab5d93051421ce25385d54dab76552b.wasm", + "tx_resign_steward.wasm": "tx_resign_steward.219a08773dc92bdd4b7452084813425960aa200c4642709dea57c8d1f17ee6ea.wasm", + "tx_reveal_pk.wasm": "tx_reveal_pk.856650de7ff63fe15962aaabaa1603bed64137fddae144c2604968d82c5a6039.wasm", + "tx_transfer.wasm": "tx_transfer.a18e0ad5635ab1503b2f97683865d8a56c3f0885d198d710f5651378f8a23856.wasm", + "tx_unbond.wasm": "tx_unbond.22e59b98be11930ac1a3facad4e4f6f9aa06341b9ab59f9dc5c5049334ce8592.wasm", + "tx_unjail_validator.wasm": "tx_unjail_validator.3a92cfd8286bdcaeb13b95faa305a1c7cec29b895e7bd6eb90c346335d872941.wasm", + "tx_update_account.wasm": "tx_update_account.f17b0f3b5704c248c32db727213dde3f29875c40454a02aa1d01152f8b17c8ba.wasm", + "tx_update_steward_commission.wasm": "tx_update_steward_commission.069fcfc27ca22da514f4a0cae50cea0a25142b265fd150c4b19a2c9e9e8e99f2.wasm", + "tx_vote_proposal.wasm": "tx_vote_proposal.b8eb3df7c4114f661cfef7c67ef6e5ee8d15e148709e6b3d7e72708c5f1f1df2.wasm", + "tx_withdraw.wasm": "tx_withdraw.48ef5ced0d783dcd28542353b56d6c6af726ca17ac351dca23ff2431aa830b7e.wasm", + "vp_implicit.wasm": "vp_implicit.835786b939e5386c96071ad217eb493bd16164a056a90e29dd50506ef2f86113.wasm", + "vp_user.wasm": "vp_user.8df002a2a325adc9c752232c6c0f24b9c56c7356e57adf5ae6672d82071cde89.wasm" } \ No newline at end of file diff --git a/wasm/tx_ibc/src/lib.rs b/wasm/tx_ibc/src/lib.rs index 9072ca7620..65bebff920 100644 --- a/wasm/tx_ibc/src/lib.rs +++ b/wasm/tx_ibc/src/lib.rs @@ -40,8 +40,8 @@ fn apply_tx(ctx: &mut Ctx, tx_data: BatchedTx) -> TxResult { if let Some(masp_section_ref) = transfers.shielded_section_hash { let shielded = tx_data .tx - .get_section(&masp_section_ref) - .and_then(|x| x.as_ref().masp_tx()) + .get_masp_section(&masp_section_ref) + .cloned() .ok_or_err_msg( "Unable to find required shielded section in tx data", ) diff --git a/wasm/tx_transfer/src/lib.rs b/wasm/tx_transfer/src/lib.rs index 6f9d9ede75..0cc58998df 100644 --- a/wasm/tx_transfer/src/lib.rs +++ b/wasm/tx_transfer/src/lib.rs @@ -40,8 +40,8 @@ fn apply_tx(ctx: &mut Ctx, tx_data: BatchedTx) -> TxResult { if let Some(masp_section_ref) = transfers.shielded_section_hash { let shielded = tx_data .tx - .get_section(&masp_section_ref) - .and_then(|x| x.as_ref().masp_tx()) + .get_masp_section(&masp_section_ref) + .cloned() .ok_or_err_msg( "Unable to find required shielded section in tx data", ) diff --git a/wasm_for_tests/Cargo.lock b/wasm_for_tests/Cargo.lock index 52e529561a..3759b88470 100644 --- a/wasm_for_tests/Cargo.lock +++ b/wasm_for_tests/Cargo.lock @@ -3568,7 +3568,7 @@ dependencies = [ [[package]] name = "masp_note_encryption" version = "1.0.0" -source = "git+https://github.com/anoma/masp?rev=71b36beba21e35f8611f3ba6910ed5b78ec11af1#71b36beba21e35f8611f3ba6910ed5b78ec11af1" +source = "git+https://github.com/anoma/masp?rev=8d83b172698098fba393006016072bc201ed9ab7#8d83b172698098fba393006016072bc201ed9ab7" dependencies = [ "borsh 1.2.1", "chacha20", @@ -3581,7 +3581,7 @@ dependencies = [ [[package]] name = "masp_primitives" version = "1.0.0" -source = "git+https://github.com/anoma/masp?rev=71b36beba21e35f8611f3ba6910ed5b78ec11af1#71b36beba21e35f8611f3ba6910ed5b78ec11af1" +source = "git+https://github.com/anoma/masp?rev=8d83b172698098fba393006016072bc201ed9ab7#8d83b172698098fba393006016072bc201ed9ab7" dependencies = [ "aes", "bip0039", @@ -3613,7 +3613,7 @@ dependencies = [ [[package]] name = "masp_proofs" version = "1.0.0" -source = "git+https://github.com/anoma/masp?rev=71b36beba21e35f8611f3ba6910ed5b78ec11af1#71b36beba21e35f8611f3ba6910ed5b78ec11af1" +source = "git+https://github.com/anoma/masp?rev=8d83b172698098fba393006016072bc201ed9ab7#8d83b172698098fba393006016072bc201ed9ab7" dependencies = [ "bellman", "blake2b_simd",