From a04f2a942f50a0796d0ccb572e4ac2a7c19edc47 Mon Sep 17 00:00:00 2001 From: sagar sapkota Date: Sun, 13 Oct 2024 13:12:24 +0545 Subject: [PATCH] audit issues fixes - second report --- contracts/asset_manager/src/contract.rs | 8 +++-- .../balanced_doller/src/balanced_dollar.rs | 2 +- contracts/xcall_manager/src/contract.rs | 4 --- .../src/tests/xcall_manager_test.rs | 31 ------------------- 4 files changed, 7 insertions(+), 38 deletions(-) diff --git a/contracts/asset_manager/src/contract.rs b/contracts/asset_manager/src/contract.rs index 2445193..e79c0f5 100644 --- a/contracts/asset_manager/src/contract.rs +++ b/contracts/asset_manager/src/contract.rs @@ -154,7 +154,7 @@ impl AssetManager { let max_withdraw = balance - min_reserve; let last_update: u64 = data.last_update; - let time_diff = (&env.ledger().timestamp() - last_update) / 1000; + let time_diff = &env.ledger().timestamp() - last_update; let allowed_withdrawal = (max_withdraw * time_diff as u128) / period; let mut reserve: u128 = data.current_limit as u128; @@ -179,6 +179,10 @@ impl AssetManager { to: Option, data: Option, ) -> Result<(), ContractError> { + if amount <= 0{ + return Err(ContractError::AmountIsLessThanMinimumAmount); + } + let deposit_to = to.unwrap_or(String::from_str(&e, "")); let deposit_data = data.unwrap_or(Bytes::from_array(&e, &[0u8; 32])); @@ -304,7 +308,7 @@ impl AssetManager { Ok(()) } - pub fn withdraw( + fn withdraw( e: &Env, from: Address, token: Address, diff --git a/contracts/balanced_doller/src/balanced_dollar.rs b/contracts/balanced_doller/src/balanced_dollar.rs index 1f69244..a4e6e47 100644 --- a/contracts/balanced_doller/src/balanced_dollar.rs +++ b/contracts/balanced_doller/src/balanced_dollar.rs @@ -11,7 +11,7 @@ use crate::{ config::{get_config, set_config, ConfigData}, xcall_manager_interface::XcallManagerClient, }; -use soroban_rlp::balanced::address_utils::{get_address_from, is_valid_bytes_address}; +use soroban_rlp::balanced::address_utils::is_valid_bytes_address; use soroban_rlp::balanced::messages::{ cross_transfer::CrossTransfer, cross_transfer_revert::CrossTransferRevert, }; diff --git a/contracts/xcall_manager/src/contract.rs b/contracts/xcall_manager/src/contract.rs index 49217d9..653caab 100644 --- a/contracts/xcall_manager/src/contract.rs +++ b/contracts/xcall_manager/src/contract.rs @@ -146,10 +146,6 @@ impl XcallManager { } actions.remove(&e, data.clone()); - if !Self::verify_protocols(e.clone(), protocols.clone())? { - return Err(ContractError::ProtocolMismatch); - }; - let method = ConfigureProtocols::get_method(&e.clone(), data.clone()); let sources = read_sources(&e); diff --git a/contracts/xcall_manager/src/tests/xcall_manager_test.rs b/contracts/xcall_manager/src/tests/xcall_manager_test.rs index c89e290..d602afa 100644 --- a/contracts/xcall_manager/src/tests/xcall_manager_test.rs +++ b/contracts/xcall_manager/src/tests/xcall_manager_test.rs @@ -337,37 +337,6 @@ fn test_handle_call_message_for_configure_protocols_panic_for_only_icon_governan assert_eq!(d, destinations); } -#[test] -#[should_panic(expected = "HostError: Error(Contract, #7)")] -fn test_handle_call_message_for_configure_protocols_panic_for_protocol_mismatch() { - let ctx = TestContext::default(); - let client = XcallManagerClient::new(&ctx.env, &ctx.registry); - ctx.env.mock_all_auths(); - ctx.init_context(&client); - - let source_items = [ - String::from_str(&ctx.env, "stellar/address"), - String::from_str(&ctx.env, "stellar/address1"), - ]; - let destination_items = [ - String::from_str(&ctx.env, "icon/address"), - String::from_str(&ctx.env, "icon/address1"), - ]; - let sources = Vec::from_array(&ctx.env, source_items); - let destinations = Vec::from_array(&ctx.env, destination_items); - let data = ConfigureProtocols::new(sources.clone(), destinations.clone()) - .encode(&ctx.env, String::from_str(&ctx.env, "ConfigureProtocols")); - let decoded: ConfigureProtocols = ConfigureProtocols::decode(&ctx.env, data.clone()); - client.white_list_actions(&data); - assert_eq!(decoded.sources, sources); - assert_eq!(decoded.destinations, destinations); - let s = Vec::from_array(&ctx.env, [ctx.xcall.to_string()]); - client.handle_call_message(&ctx.icon_governance, &data, &s); - - let (s, d) = client.get_protocols(); - assert_eq!(s, sources); - assert_eq!(d, destinations); -} #[test] #[should_panic(expected = "HostError: Error(Contract, #10)")]