Skip to content

Commit

Permalink
fix(cast): do not strip 0x / hex decode message before EIP-191 hashing (
Browse files Browse the repository at this point in the history
foundry-rs#9130)

* fix(cast): do not strip 0x / hex decode message before encoding

* Pass message directly to eip191_hash_message
  • Loading branch information
grandizzy authored and rplusq committed Nov 29, 2024
1 parent a3ea2a5 commit 5a2c6d5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
6 changes: 1 addition & 5 deletions crates/cast/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/cast/tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ casttest!(hash_message, |_prj, cmd| {
"#]]);

cmd.cast_fuse().args(["hash-message", "0x68656c6c6f"]).assert_success().stdout_eq(str![[r#"
0x50b2c43fd39106bafbba0da34fc430e1f91e3c96ea2acee2bc34119f92b37750
0x83a0870b6c63a71efdd3b2749ef700653d97454152c4b53fa9b102dc430c7c32
"#]]);
});

0 comments on commit 5a2c6d5

Please sign in to comment.