From 5a2c6d598da354549d864892db8f806005cd9d4d Mon Sep 17 00:00:00 2001 From: grandizzy <38490174+grandizzy@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:20:55 +0300 Subject: [PATCH] fix(cast): do not strip 0x / hex decode message before EIP-191 hashing (#9130) * fix(cast): do not strip 0x / hex decode message before encoding * Pass message directly to eip191_hash_message --- crates/cast/bin/main.rs | 6 +----- crates/cast/tests/cli/main.rs | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/crates/cast/bin/main.rs b/crates/cast/bin/main.rs index 63894d980b0ab..607f4439188ac 100644 --- a/crates/cast/bin/main.rs +++ b/crates/cast/bin/main.rs @@ -533,11 +533,7 @@ async fn main_args(args: CastArgs) -> Result<()> { } CastSubcommand::HashMessage { message } => { let message = stdin::unwrap_line(message)?; - let input = match message.strip_prefix("0x") { - Some(hex_str) => hex::decode(hex_str)?, - None => message.as_bytes().to_vec(), - }; - println!("{}", eip191_hash_message(input)); + println!("{}", eip191_hash_message(message)); } CastSubcommand::SigEvent { event_string } => { let event_string = stdin::unwrap_line(event_string)?; diff --git a/crates/cast/tests/cli/main.rs b/crates/cast/tests/cli/main.rs index 9f198a5393db3..b0a0f42a242b0 100644 --- a/crates/cast/tests/cli/main.rs +++ b/crates/cast/tests/cli/main.rs @@ -1387,7 +1387,7 @@ casttest!(hash_message, |_prj, cmd| { "#]]); cmd.cast_fuse().args(["hash-message", "0x68656c6c6f"]).assert_success().stdout_eq(str![[r#" -0x50b2c43fd39106bafbba0da34fc430e1f91e3c96ea2acee2bc34119f92b37750 +0x83a0870b6c63a71efdd3b2749ef700653d97454152c4b53fa9b102dc430c7c32 "#]]); });