Skip to content

Commit

Permalink
⚡️ Use an addr instead of str for map key
Browse files Browse the repository at this point in the history
- avoid any issues with upper/lower case that can cause a bypass of the blocked address list
  • Loading branch information
NotJeremyLiu committed Jul 6, 2023
1 parent 650de03 commit fe4a55e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions contracts/entry-point/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn instantiate(
let mut response: Response = Response::new().add_attribute("action", "instantiate");

// Insert the entry point contract address into the blocked contract addresses map
BLOCKED_CONTRACT_ADDRESSES.save(deps.storage, env.contract.address.as_str(), &())?;
BLOCKED_CONTRACT_ADDRESSES.save(deps.storage, &env.contract.address, &())?;

// Iterate through the swap venues provided and create a map of venue names to swap adapter contract addresses
for swap_venue in msg.swap_venues.iter() {
Expand All @@ -46,7 +46,7 @@ pub fn instantiate(
)?;

// Insert the swap contract address into the blocked contract addresses map
BLOCKED_CONTRACT_ADDRESSES.save(deps.storage, &swap_venue.adapter_contract_address, &())?;
BLOCKED_CONTRACT_ADDRESSES.save(deps.storage, &checked_swap_contract_address, &())?;

// Add the swap venue and contract address to the response
response = response
Expand All @@ -63,7 +63,7 @@ pub fn instantiate(
IBC_TRANSFER_CONTRACT_ADDRESS.save(deps.storage, &checked_ibc_transfer_contract_address)?;

// Insert the ibc transfer adapter contract address into the blocked contract addresses map
BLOCKED_CONTRACT_ADDRESSES.save(deps.storage, &msg.ibc_transfer_contract_address, &())?;
BLOCKED_CONTRACT_ADDRESSES.save(deps.storage, &checked_ibc_transfer_contract_address, &())?;

// Add the ibc transfer adapter contract address to the response
response = response
Expand Down
4 changes: 2 additions & 2 deletions contracts/entry-point/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,10 @@ fn verify_and_create_contract_call_msg(
transfer_out_coin: Coin,
) -> ContractResult<WasmMsg> {
// Verify the contract address is valid, error if invalid
deps.api.addr_validate(&contract_address)?;
let checked_contract_address = deps.api.addr_validate(&contract_address)?;

// Error if the contract address is in the blocked contract addresses map
if BLOCKED_CONTRACT_ADDRESSES.has(deps.storage, &contract_address) {
if BLOCKED_CONTRACT_ADDRESSES.has(deps.storage, &checked_contract_address) {
return Err(ContractError::ContractCallAddressBlocked);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/entry-point/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_std::Addr;
use cw_storage_plus::{Item, Map};

pub const BLOCKED_CONTRACT_ADDRESSES: Map<&str, ()> = Map::new("blocked_contract_addresses");
pub const BLOCKED_CONTRACT_ADDRESSES: Map<&Addr, ()> = Map::new("blocked_contract_addresses");
pub const SWAP_VENUE_MAP: Map<&str, Addr> = Map::new("swap_venue_map");
pub const IBC_TRANSFER_CONTRACT_ADDRESS: Item<Addr> = Item::new("ibc_transfer_contract_address");
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ fn test_execute_post_swap_action(params: Params) {

// Store the entry point contract address in the blocked contract addresses map
BLOCKED_CONTRACT_ADDRESSES
.save(deps.as_mut().storage, "entry_point", &())
.save(deps.as_mut().storage, &Addr::unchecked("entry_point"), &())
.unwrap();

// Call execute_post_swap_action with the given test parameters
Expand Down

0 comments on commit fe4a55e

Please sign in to comment.