From 19f8eb703a8ea7b8503c89c3884eb74895d04b23 Mon Sep 17 00:00:00 2001 From: grandizzy Date: Wed, 16 Oct 2024 20:41:07 +0300 Subject: [PATCH 1/2] fix(cast): do not strip 0x / hex decode message before encoding --- crates/cast/bin/main.rs | 5 +---- crates/cast/tests/cli/main.rs | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/cast/bin/main.rs b/crates/cast/bin/main.rs index 63894d980b0a..dddb53c210fa 100644 --- a/crates/cast/bin/main.rs +++ b/crates/cast/bin/main.rs @@ -533,10 +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(), - }; + let input = message.as_bytes().to_vec(); println!("{}", eip191_hash_message(input)); } CastSubcommand::SigEvent { event_string } => { diff --git a/crates/cast/tests/cli/main.rs b/crates/cast/tests/cli/main.rs index df566d1144c0..be9ccc168c11 100644 --- a/crates/cast/tests/cli/main.rs +++ b/crates/cast/tests/cli/main.rs @@ -1322,7 +1322,7 @@ casttest!(hash_message, |_prj, cmd| { "#]]); cmd.cast_fuse().args(["hash-message", "0x68656c6c6f"]).assert_success().stdout_eq(str![[r#" -0x50b2c43fd39106bafbba0da34fc430e1f91e3c96ea2acee2bc34119f92b37750 +0x83a0870b6c63a71efdd3b2749ef700653d97454152c4b53fa9b102dc430c7c32 "#]]); }); From 942dc317918cbb99e5bd740a3177bdbd6a1d9772 Mon Sep 17 00:00:00 2001 From: grandizzy Date: Wed, 16 Oct 2024 23:37:46 +0300 Subject: [PATCH 2/2] Pass message directly to eip191_hash_message --- crates/cast/bin/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/cast/bin/main.rs b/crates/cast/bin/main.rs index dddb53c210fa..607f4439188a 100644 --- a/crates/cast/bin/main.rs +++ b/crates/cast/bin/main.rs @@ -533,8 +533,7 @@ async fn main_args(args: CastArgs) -> Result<()> { } CastSubcommand::HashMessage { message } => { let message = stdin::unwrap_line(message)?; - let input = 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)?;