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

feat(cast): add string-decode to decode string #9237

Merged
merged 5 commits into from
Oct 31, 2024

Conversation

jsvisa
Copy link
Contributor

@jsvisa jsvisa commented Oct 31, 2024

Motivation

When I'm debugging some transactions that we reverted, what I got from the tx's trace as below:

{
  "from": "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed",
  "gas": "0x0",
  "gasUsed": "0x0",
  "to": "0x5ff0bea4603b68c7e80b8a973a666b9840db248c",
  "input": "0x6a76120200000000000000000000000034053113b5ddc6fb368e4d028c1bbbcb85c14ef1...",
  "output": "0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000054753303235000000000000000000000000000000000000000000000000000000",
  "error": "execution reverted",
  "calls": [
    {
      "from": "0x5ff0bea4603b68c7e80b8a973a666b9840db248c",
      "gas": "0xbbf0",
      "gasUsed": "0x24cc",
      "to": "0x632cd990566bc2cc888f75c9bbe8b9185a91d24d",
      "input": "0x6a76120200000000000000000000000034053113b5ddc6fb368e4d028c1bbbcb85c14ef1...",
      "output": "0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000054753303235000000000000000000000000000000000000000000000000000000",
      "error": "execution reverted",
      "type": "DELEGATECALL"
    }
  ],
  "value": "0x0",
  "type": "CALL"
}

And this output is ABI-encode of Error(string), so I think we can add a simple command to decode the ABI-string into human readable msg, for this case:

$ ./target/release/cast 
 string-decode 0x88c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000054753303235000000000000000000000000000000000000000000000000000000

"GS025"

Inspired from https://ethereum.stackexchange.com/a/77530

Solution

Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

sounds reasonable to me
wdyt @grandizzy

Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

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

makes sense, thank you! @jsvisa could you please also add a test, here's a sample:

casttest!(parse_units, |_prj, cmd| {
cmd.args(["parse-units", "1.5", "6"]).assert_success().stdout_eq(str![[r#"
1500000

Signed-off-by: jsvisa <delweng@gmail.com>
@jsvisa jsvisa requested a review from grandizzy October 31, 2024 08:59
crates/cast/bin/args.rs Outdated Show resolved Hide resolved
crates/cast/bin/args.rs Outdated Show resolved Hide resolved
crates/cast/bin/args.rs Outdated Show resolved Hide resolved
Copy link
Member

@zerosnacks zerosnacks left a comment

Choose a reason for hiding this comment

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

Applied minor documentation fixes, proposed goal is reasonable + implementation LGTM

@zerosnacks zerosnacks enabled auto-merge (squash) October 31, 2024 09:19
@zerosnacks zerosnacks merged commit 736a330 into foundry-rs:master Oct 31, 2024
21 checks passed
@jsvisa jsvisa deleted the cast-ed branch October 31, 2024 09:29
rplusq pushed a commit to rplusq/foundry that referenced this pull request Nov 29, 2024
* feat(cast): add error-decode to decode error string

Signed-off-by: jsvisa <delweng@gmail.com>

* feat(cast): error-decode -> string-decode

Signed-off-by: jsvisa <delweng@gmail.com>

* add test case for string-decode

Signed-off-by: jsvisa <delweng@gmail.com>

* Apply suggestions from code review

---------

Signed-off-by: jsvisa <delweng@gmail.com>
Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
@grandizzy grandizzy added T-feature Type: feature 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-feature Type: feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants