Skip to content

Remove PartialEq between &str/String and Addr #1669

Closed
@webmaster128

Description

@webmaster128

When one of the sides is not normalized you can get unintended results. E.g.

fn my_func(deps: Deps, user_provided_address: &str) {

   let existing_address: Addr = CONFIG.load(deps.storage)?.blocked;

   if user_provided_address != blocked {
        return Err(ContractError::Unauthorized);
   }
}

Now if blocked is cosmos1jhg0e7s6gn44tfc5k37kr04sznyhedtc9rzys5 and user_provided_address is cosmos1jhg0e7s6gn44tfc5k37kr04sznyhedtc9rzys5 the check works fine. But if the perfectly valid form COSMOS1JHG0E7S6GN44TFC5K37KR04SZNYHEDTC9RZYS5 is provided, this breaks.

I'm sure the example is bad here but I hope you get what I mean. Equality checkes between Addr and &str or String are just not safe.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions