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

cast run does not decode calldata for library (delegate-)call. #5950

Closed
2 tasks done
ckoopmann opened this issue Sep 29, 2023 · 6 comments · Fixed by #9399
Closed
2 tasks done

cast run does not decode calldata for library (delegate-)call. #5950

ckoopmann opened this issue Sep 29, 2023 · 6 comments · Fixed by #9399
Assignees
Labels
C-cast Command: cast P-low Priority: low T-bug Type: bug

Comments

@ckoopmann
Copy link
Contributor

Component

Cast

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

cast 0.2.0 (96ab913 2023-09-28T00:20:52.150553000Z)

What command(s) is the bug in?

cast run

Operating System

macOS (Apple Silicon)

Describe the bug

When running cast run on a transaction that includes delegatecalls to a library deployment, those calls are not decoded correctly in the transaction traces, even though the libraries source code is verified on etherscan.

When running cast run --rpc-url <ETH_MAINNET_RPC_URL> --quick 0x07a6ad95d76f4c1318d38564439347b39a47b126a7cbd3fe0b58a980392d4a35 the delegate calls are shown as:
image

Whereas I'd expect them to be decoded using the library's abi. (In above case it would be the swapExactTokensForTokens(DEXAdapter.Addresses,uint256,uint256,DEXAdapter.SwapData) selector.

Note that I haven't verified this behaviour for other library deployments yet, so it could be caused by something in this specific signature / example as well.

@ckoopmann ckoopmann added the T-bug Type: bug label Sep 29, 2023
@gakonst gakonst added this to Foundry Sep 29, 2023
@github-project-automation github-project-automation bot moved this to Todo in Foundry Sep 29, 2023
@ckoopmann
Copy link
Contributor Author

ckoopmann commented Sep 29, 2023

Just noted that for libraries (or at least this specific one) etherscan does not show any external / public "write functions" even though there are "external" functions defined in the source code.

Maybe this is expected behaviour since this library is not meant to be called except for delegatecalls.

However it would be great to find a workaround for this on the cast side, since it currently kind of breaks the tx debug workflow by requiring users to manually decode these calls using cast abi-decode or similar tools.

image image

@ckoopmann
Copy link
Contributor Author

Etherscan api also does not include these methods in the abi returned by the api, so probably non-trivial to find a workaround for this.

https://api.etherscan.io/api
   ?module=contract
   &action=getabi
   &address=0xBb02bCCE1bdcc0b07E7870346D8b2ad9397D0fAC
   &apikey=<YOUR_ETHERSCAN_API_KEY>
image

@ckoopmann
Copy link
Contributor Author

ckoopmann commented Sep 29, 2023

For anyone facing the same issue, the manual workaround I did is:

  1. Copy calldata from trace (everything inside the brackets)
  2. Determine the called function signature by using solc --hashes and comparing the resulting output to the hash shown in the trace
  3. Decode calldata using cast and the function signature: cast abi-decode --input "swapExactTokensForTokens((address,address,address,address,address,address,address),uint256,uint256,(address[],uint24[],address,uint8))" <CALLDATA>

This is a bit of a pain though (especially step 2) and took me > 1 hour to get right, so definetely would be great to find a workaround inside cast for this.

@ckoopmann
Copy link
Contributor Author

After revisiting this I noticed that we seem to use exclusively the openchain api to decode all traces. (and not from etherscan).
This api does not seem to contain signatures for library functions, meaning in the above example the following query:
https://api.openchain.xyz/signature-database/v1/lookup?function=0x1aafa9d8

Returns {"ok":true,"result":{"event":{},"function":{"0x1aafa9d8":null}}} which then results in the trace not being decoded.

@ckoopmann
Copy link
Contributor Author

Opened an issue on openchain repo to see if their service can be extended to be able to decode these types of signatures:
openchainxyz/openchain-monorepo#21

@zerosnacks zerosnacks added the C-cast Command: cast label Jul 4, 2024
@zerosnacks
Copy link
Member

Able to reproduce with given setup

For future reference

0xBb02bCCE1bdcc0b07E7870346D8b2ad9397D0fAC::1aafa9d8(0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564000000000000000000000000b27308f9f90d607463bb33ea1bebb41c27ce5ab60000000000000000000000000000000022d53366457f9d5e68ec105046fc4383000000000000000000000000c1db00a8e5ef7bfa476395cdbcc98235477cde4e000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000154e02c00000000000000000000000000000000000000000000000031548ccf80b0c0f90000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000030000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001f400000000000000000000000000000000000000000000000000000000000001f4) [delegatecall]

@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 26, 2024
@grandizzy grandizzy removed this from the v1.0.0 milestone Oct 29, 2024
@grandizzy grandizzy added the P-low Priority: low label Oct 29, 2024
@grandizzy grandizzy self-assigned this Nov 25, 2024
@grandizzy grandizzy moved this from Todo to Ready For Review in Foundry Nov 25, 2024
@github-project-automation github-project-automation bot moved this from Ready For Review to Done in Foundry Nov 28, 2024
@grandizzy grandizzy moved this from Done to Completed in Foundry Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cast Command: cast P-low Priority: low T-bug Type: bug
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

3 participants