Skip to content

fix(cast): read all lines for message to hash #10671

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

Merged

Conversation

grandizzy
Copy link
Collaborator

Motivation

#!/usr/bin/env bash
message_raw=$(<message.txt)
hashed_message1=$(printf "%s" "$message_raw" | cast hash-message)
hashed_message2=$(cast hash-message "$message_raw")
echo $hashed_message1
echo $hashed_message2

where message.txt is something like

Welcome to OpenSea!

Click to sign in and accept the OpenSea Terms of Service (https://opensea.io/tos) and Privacy Policy (https://opensea.io/privacy).

This request will not trigger a blockchain transaction or cost any gas fees.

outputs different hashes

0xc36550d1b80343edd49ced11158a478faf57dbec05ade0b463149bc7b31d8df8
0x9ae3cff27abb1798440be7218c7c62070e7fca99d0a3b68b6ef451d64b15ba63

because in 1st case only first line is read

Solution

  • use stdin::unwrap(message, false)? to read message

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@grandizzy grandizzy marked this pull request as ready for review May 30, 2025 11:24
@grandizzy grandizzy added T-bug Type: bug C-cast Command: cast labels May 30, 2025
@grandizzy grandizzy merged commit 788ba28 into foundry-rs:master May 30, 2025
22 checks passed
@grandizzy grandizzy deleted the hash-message-read-no-unwrap-line branch May 30, 2025 11:27
@github-project-automation github-project-automation bot moved this to Done in Foundry May 30, 2025
grandizzy added a commit to grandizzy/foundry that referenced this pull request May 30, 2025
grandizzy added a commit that referenced this pull request May 30, 2025
….2.2) (#10672)

fix(cast): read all lines for message to hash (#10671)
pcaversaccio added a commit to pcaversaccio/safe-tx-hashes-util that referenced this pull request Jun 2, 2025
### 🕓 Changelog

This commit fixes the `Argument list too long` errors (see, e.g.,
[here](foundry-rs/foundry#10659)) by piping
the (potentially very) large inputs to `cast keccak` and `cast
hash-message` via `stdin` instead of passing it as a command-line
argument. Please note that this PR relies on the patch for `cast
hash-message` introduced in
[foundry-rs/foundry#10671](foundry-rs/foundry#10671),
included in Foundry
[`1.2.2`](https://github.com/foundry-rs/foundry/releases/tag/v1.2.2) and
available in the latest _stable_ release of `cast`.

### Test Example

```console
./safe_hashes.sh --network zksync --address 0x9fb5F754f5222449F98b904a34494cB21AADFdf8 --nonce 12
```

> Select `1` for "Please enter the index of the array:".

returns:

```console
===================================
= Selected Network Configurations =
===================================

Network: zksync
Chain ID: 324

========================================
= Transaction Data and Computed Hashes =
========================================

> Transaction Data:
Multisig address: 0x9fb5F754f5222449F98b904a34494cB21AADFdf8
To: 0xCC926359DBE6b6311D63f8155fcC3B57F3fAAE80
Value: 0
Data: 0x... (very large; omitted here)
Operation: Call
Safe Transaction Gas: 0
Base Gas: 0
Gas Price: 0
Gas Token: 0x0000000000000000000000000000000000000000
Refund Receiver: 0x0000000000000000000000000000000000000000
Nonce: 12
Encoded message: 0xbb8310d486368db6bd6f849402fdd73ad53d316b5a4b2644ad6efe0f941286d8000000000000000000000000cc926359dbe6b6311d63f8155fcc3b57f3faae800000000000000000000000000000000000000000000000000000000000000000390de467d7c8f2ce53221c9e9b8961d6f95a9bac95c8d64860569536e2530d7f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c
Method: Unknown
Parameters: Unknown

> Hashes:
Domain hash: 0x44B7F5D3633D89B36226C7C3FE506E64904143C6289D42E5EAE52EAB28D1B034
Message hash: 0x5FF90C7690C66DE45D4D84AE5BE2F7D4722E6236DBEB223B9450F7FC28ADA78D
Safe transaction hash: 0x8bf43f38a201cef8317d773de616d0dc75115c84d83fad4388f691cc00acd538
```

Now compare with
https://app.safe.global/transactions/tx?safe=zksync:0x9fb5F754f5222449F98b904a34494cB21AADFdf8&id=multisig_0x9fb5F754f5222449F98b904a34494cB21AADFdf8_0x8bf43f38a201cef8317d773de616d0dc75115c84d83fad4388f691cc00acd538.

This PR also adds `https://etherscan.io` to the `awesome_bot` whitelist
in the CI pipeline `checks.yml`.

---------

Signed-off-by: Pascal Marco Caversaccio <[email protected]>
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
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants