From dd256452a4196f2c8bcd06934cc75cde8b53b088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rare=C8=99?= <6453351+raress96@users.noreply.github.com> Date: Mon, 7 Oct 2024 09:28:13 +0300 Subject: [PATCH] fix(minor-ampd): update MultiversX sdk to fix transaction not being verified bug (#645) --- Cargo.lock | 55 +++++++++++++++++++++++++------ ampd/Cargo.toml | 2 +- ampd/src/lib.rs | 6 ++-- ampd/src/mvx/proxy.rs | 70 ++++++++++++++++++++++++++++++++++++++-- ampd/src/mvx/verifier.rs | 14 ++++---- 5 files changed, 125 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ca3b1894..615185d5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3025,7 +3025,7 @@ dependencies = [ "proc-macro2 1.0.85", "quote 1.0.36", "syn 2.0.68", - "uuid 1.8.0", + "uuid 1.10.0", ] [[package]] @@ -5066,27 +5066,32 @@ dependencies = [ [[package]] name = "multiversx-sdk" -version = "0.4.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cb2f8dd4a17ce9c9fa1ab3d80152929702968be6536499f32bd7e2278c2e0fb" +checksum = "ccf9bc1c31815db80017c68353b7187bc606b573af26f13331e9507d29f1976f" dependencies = [ + "aes", "anyhow", "base64 0.22.1", - "bech32 0.9.1", + "bech32 0.11.0", "bip39", + "ctr", "hex", "hmac", - "itertools 0.12.1", + "itertools 0.13.0", + "log", "pbkdf2", "pem 3.0.4", "rand", "reqwest 0.12.5", + "scrypt", "serde", "serde_json", "serde_repr", "sha2 0.10.8", "sha3", "tokio", + "uuid 1.10.0", "zeroize", ] @@ -5107,7 +5112,7 @@ dependencies = [ "tap", "tokio", "tracing", - "uuid 1.8.0", + "uuid 1.10.0", ] [[package]] @@ -5721,6 +5726,17 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "password-hash" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166" +dependencies = [ + "base64ct", + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "pasta_curves" version = "0.5.1" @@ -7155,6 +7171,15 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "salsa20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213" +dependencies = [ + "cipher", +] + [[package]] name = "same-file" version = "1.0.6" @@ -7228,6 +7253,18 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "scrypt" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0516a385866c09368f0b5bcd1caff3366aace790fcd46e2bb032697bb172fd1f" +dependencies = [ + "password-hash", + "pbkdf2", + "salsa20", + "sha2 0.10.8", +] + [[package]] name = "sct" version = "0.6.1" @@ -9008,7 +9045,7 @@ dependencies = [ "tower-layer", "tower-service", "tracing", - "uuid 1.8.0", + "uuid 1.10.0", ] [[package]] @@ -9326,9 +9363,9 @@ checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" [[package]] name = "uuid" -version = "1.8.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" +checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" dependencies = [ "getrandom", "rand", diff --git a/ampd/Cargo.toml b/ampd/Cargo.toml index ed3bb1563..d8f7659d9 100644 --- a/ampd/Cargo.toml +++ b/ampd/Cargo.toml @@ -38,7 +38,7 @@ k256 = { workspace = true } mockall = "0.11.3" move-core-types = { git = "https://github.com/mystenlabs/sui", tag = "mainnet-v1.26.2" } multisig = { workspace = true, features = ["library"] } -multiversx-sdk = "0.4.1" +multiversx-sdk = "0.6.1" num-traits = { workspace = true } openssl = { version = "0.10.35", features = ["vendored"] } # Needed to make arm compilation work by forcing vendoring prost = "0.11.9" diff --git a/ampd/src/lib.rs b/ampd/src/lib.rs index 7662f2935..c6b774df9 100644 --- a/ampd/src/lib.rs +++ b/ampd/src/lib.rs @@ -11,7 +11,7 @@ use event_processor::EventHandler; use event_sub::EventSub; use evm::finalizer::{pick, Finalization}; use evm::json_rpc::EthereumClient; -use multiversx_sdk::blockchain::CommunicationProxy; +use multiversx_sdk::gateway::GatewayProxy; use queue::queued_broadcaster::QueuedBroadcaster; use router_api::ChainName; use thiserror::Error; @@ -338,7 +338,7 @@ where handlers::mvx_verify_msg::Handler::new( verifier.clone(), cosmwasm_contract, - CommunicationProxy::new(proxy_url.to_string().trim_end_matches('/').into()), + GatewayProxy::new(proxy_url.to_string().trim_end_matches('/').into()), self.block_height_monitor.latest_block_height(), ), event_processor_config.clone(), @@ -351,7 +351,7 @@ where handlers::mvx_verify_verifier_set::Handler::new( verifier.clone(), cosmwasm_contract, - CommunicationProxy::new(proxy_url.to_string().trim_end_matches('/').into()), + GatewayProxy::new(proxy_url.to_string().trim_end_matches('/').into()), self.block_height_monitor.latest_block_height(), ), event_processor_config.clone(), diff --git a/ampd/src/mvx/proxy.rs b/ampd/src/mvx/proxy.rs index de5299c4e..a5646ca80 100644 --- a/ampd/src/mvx/proxy.rs +++ b/ampd/src/mvx/proxy.rs @@ -4,8 +4,8 @@ use async_trait::async_trait; use futures::future::join_all; use hex::ToHex; use mockall::automock; -use multiversx_sdk::blockchain::CommunicationProxy; use multiversx_sdk::data::transaction::TransactionOnNetwork; +use multiversx_sdk::gateway::GatewayProxy; use crate::types::Hash; @@ -25,7 +25,7 @@ pub trait MvxProxy { } #[async_trait] -impl MvxProxy for CommunicationProxy { +impl MvxProxy for GatewayProxy { async fn transactions_info_with_results( &self, tx_hashes: HashSet, @@ -61,3 +61,69 @@ impl MvxProxy for CommunicationProxy { tx.hash.is_some() && tx.logs.is_some() && tx.status == *STATUS_SUCCESS } } + +#[cfg(test)] +mod tests { + use multiversx_sdk::data::address::Address; + use multiversx_sdk::data::transaction::{ApiLogs, TransactionOnNetwork}; + use multiversx_sdk::gateway::GatewayProxy; + + use super::MvxProxy; + + #[test] + fn should_not_be_valid_transaction_no_hash() { + let tx = TransactionOnNetwork { + hash: None, + ..TransactionOnNetwork::default() + }; + + assert!(!GatewayProxy::is_valid_transaction(&tx)); + } + + #[test] + fn should_not_be_valid_transaction_no_logs() { + let tx = TransactionOnNetwork { + hash: Some("txHash".into()), + logs: None, + ..TransactionOnNetwork::default() + }; + + assert!(!GatewayProxy::is_valid_transaction(&tx)); + } + + #[test] + fn should_not_be_valid_transaction_invalid_status() { + let tx = TransactionOnNetwork { + hash: Some("txHash".into()), + logs: Some(ApiLogs { + address: Address::from_bech32_string( + "erd1qqqqqqqqqqqqqpgqhe8t5jewej70zupmh44jurgn29psua5l2jps3ntjj3", + ) + .unwrap(), + events: vec![], + }), + status: "pending".into(), + ..TransactionOnNetwork::default() + }; + + assert!(!GatewayProxy::is_valid_transaction(&tx)); + } + + #[test] + fn should_be_valid_transaction() { + let tx = TransactionOnNetwork { + hash: Some("txHash".into()), + logs: Some(ApiLogs { + address: Address::from_bech32_string( + "erd1qqqqqqqqqqqqqpgqhe8t5jewej70zupmh44jurgn29psua5l2jps3ntjj3", + ) + .unwrap(), + events: vec![], + }), + status: "success".into(), + ..TransactionOnNetwork::default() + }; + + assert!(GatewayProxy::is_valid_transaction(&tx)); + } +} diff --git a/ampd/src/mvx/verifier.rs b/ampd/src/mvx/verifier.rs index 3b201471a..d2933adc8 100644 --- a/ampd/src/mvx/verifier.rs +++ b/ampd/src/mvx/verifier.rs @@ -162,7 +162,7 @@ mod tests { use multisig::key::KeyType; use multisig::test::common::{build_verifier_set, ed25519_test_data}; use multiversx_sdk::data::address::Address; - use multiversx_sdk::data::transaction::{ApiLogs, Events, TransactionOnNetwork}; + use multiversx_sdk::data::transaction::{ApiLogs, Events, LogData, TransactionOnNetwork}; use crate::handlers::mvx_verify_msg::Message; use crate::handlers::mvx_verify_verifier_set::VerifierSetConfirmation; @@ -430,7 +430,7 @@ mod tests { address: gateway_address.clone(), identifier: CONTRACT_CALL_IDENTIFIER.into(), topics: Some(vec![STANDARD.encode(SIGNERS_ROTATED_EVENT)]), // wrong event name - data: None, + data: LogData::Empty, }; // On MultiversX, topics and data are base64 encoded @@ -444,7 +444,7 @@ mod tests { STANDARD.encode(msg.destination_address.clone()), STANDARD.encode(payload_hash), ]), - data: Some("".into()), // data is irrelevant here since it contains only the offchain payload + data: LogData::String("".into()), // data is irrelevant here since it contains only the offchain payload }; let other_address = Address::from_bech32_string( @@ -483,7 +483,7 @@ mod tests { data: None, hyperblock_nonce: Some(1), hyperblock_hash: Some("".into()), - smart_contract_results: None, + smart_contract_results: vec![], processing_type_on_destination: "".into(), }; @@ -526,7 +526,7 @@ mod tests { address: gateway_address.clone(), identifier: ROTATE_SIGNERS_IDENTIFIER.into(), topics: Some(vec![STANDARD.encode(CONTRACT_CALL_EVENT)]), // wrong event name - data: None, + data: LogData::Empty, }; // On MultiversX, topics and data are base64 encoded @@ -538,7 +538,7 @@ mod tests { STANDARD.encode("0"), // epoch (irrelevant here) STANDARD.encode(signers_hash), // signers hash ]), - data: Some(STANDARD.encode(data)), + data: LogData::String(STANDARD.encode(data)), }; let other_address = Address::from_bech32_string( @@ -577,7 +577,7 @@ mod tests { data: None, hyperblock_nonce: Some(1), hyperblock_hash: Some("".into()), - smart_contract_results: None, + smart_contract_results: vec![], processing_type_on_destination: "".into(), };