Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cast): do not strip 0x / hex decode message before EIP-191 hashing #9130

Merged
merged 2 commits into from
Oct 17, 2024

Conversation

grandizzy
Copy link
Collaborator

Motivation

  • attempts to use cast hm to create flashbot sig failed, eventually used chisel eval to generate such
chisel eval 'keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n66","'$payload_keccak'"))'

https://github.com/pcaversaccio/white-hat-frontrunning/blob/main/go.sh#L62

  • fix cast to not hex decode message to hash but use it as it is to create EIP-191 final message "\x19Ethereum Signed Message:\n" + message. length + message which is then hashed

Solution

@grandizzy grandizzy marked this pull request as ready for review October 16, 2024 18:14
Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine, however it is a breaking change, and it might be assumed that 0x input is hex decoded like in other commands, we don't really have a consistent behavior in this regard I think

crates/cast/bin/main.rs Outdated Show resolved Hide resolved
@grandizzy
Copy link
Collaborator Author

grandizzy commented Oct 17, 2024

I think this is fine, however it is a breaking change, and it might be assumed that 0x input is hex decoded like in other commands, we don't really have a consistent behavior in this regard I think

yep it is a breaking change, though the command help reads

Hash a message according to EIP-191
Usage: cast hash-message [MESSAGE]

Arguments:
  [MESSAGE]  The message to hash

so it's confusing as one would expect to just hash without decoding (also atm there's no way to hash a 0x message). We could add a cast hash-decode-message for current behavior in case there are people using it as designed now, but not sure if worth, wdyt?

@grandizzy grandizzy merged commit ca49147 into foundry-rs:master Oct 17, 2024
21 checks passed
@grandizzy grandizzy deleted the eip191-fix branch October 17, 2024 10:20
pcaversaccio added a commit to pcaversaccio/white-hat-frontrunning that referenced this pull request Oct 18, 2024
### 🕓 Changelog

Refactor to use `cast hash-message` directly, deprecating the need for
`chisel` (see [PR
#9130](foundry-rs/foundry#9130)). Additionally,
include a note highlighting the need to set the `FLASHBOTS_SIGNATURE_PK`
environment variable for proper functionality.

---------

Signed-off-by: Pascal Marco Caversaccio <[email protected]>
rplusq pushed a commit to rplusq/foundry that referenced this pull request Nov 29, 2024
foundry-rs#9130)

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

* Pass message directly to eip191_hash_message
@grandizzy grandizzy added T-bug Type: bug C-cast Command: cast labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cast Command: cast T-bug Type: bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants