From 7b2208318badf7d396f1e2de8f1f67293263d3aa Mon Sep 17 00:00:00 2001 From: Igor Line Date: Fri, 8 Sep 2023 23:42:26 +0200 Subject: [PATCH] fix: add $ to suffix regex to ensure wallet address ending with specified hex string --- crates/cast/bin/cmd/create2.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/cast/bin/cmd/create2.rs b/crates/cast/bin/cmd/create2.rs index e51cdd91df9c0..911292da6744f 100644 --- a/crates/cast/bin/cmd/create2.rs +++ b/crates/cast/bin/cmd/create2.rs @@ -96,9 +96,10 @@ impl Create2Args { )); } if let Some(suffix) = ends_with { - regexs.push( - (get_regex_hex_string(suffix).wrap_err("invalid suffix hex provided")?).to_string(), - ); + regexs.push(format!( + r"{}$", + get_regex_hex_string(suffix).wrap_err("invalid prefix hex provided")? + )) } debug_assert!( @@ -204,6 +205,14 @@ mod tests { assert!(address.starts_with("aaa")); + // odd hex chars with 0x suffix + let args = Create2Args::parse_from(["foundry-cli", "--ends-with", "bb"]); + let create2_out = args.run().unwrap(); + let address = create2_out.address; + let address = format!("{address:x}"); + + assert!(address.ends_with("bb")); + // check fails on wrong chars let args = Create2Args::parse_from(["foundry-cli", "--starts-with", "0xerr"]); let create2_out = args.run();