Skip to content

Commit

Permalink
audit issues fixes - second report
Browse files Browse the repository at this point in the history
  • Loading branch information
sagars authored and Itshyphen committed Oct 13, 2024
1 parent 163ba2b commit a04f2a9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 38 deletions.
8 changes: 6 additions & 2 deletions contracts/asset_manager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -179,6 +179,10 @@ impl AssetManager {
to: Option<String>,
data: Option<Bytes>,
) -> 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]));

Expand Down Expand Up @@ -304,7 +308,7 @@ impl AssetManager {
Ok(())
}

pub fn withdraw(
fn withdraw(
e: &Env,
from: Address,
token: Address,
Expand Down
2 changes: 1 addition & 1 deletion contracts/balanced_doller/src/balanced_dollar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
4 changes: 0 additions & 4 deletions contracts/xcall_manager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 0 additions & 31 deletions contracts/xcall_manager/src/tests/xcall_manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)")]
Expand Down

0 comments on commit a04f2a9

Please sign in to comment.