feat(`cast`): `cast abi-decode` output should be compatible with `cast call` input
Component
Cast
Describe the feature you would like
motivation:
Wanted to investigate a failed attempt to estimate gas. Could not find a trace option for cast estimate, so opted for cast call.
Having the raw function call at-hand, fed it into cast ad. I then massaged the output a bit and sent it as input to cast call --trace.
problem
The above works, but requires format adjustments that I think can be addressed by the tool. While the order and general format of cast ads output matches cast calls expectations, the following discrepancies exist:
bytes4values emitted bycast adare 0-padded to 32 bytes.cast callexpects just the 4byte hex string, sans-padding.unit256values are emitted as a pair: the integral value, followed by a scientific representation, in square brackets.cast callexpects just the integral value. (there may be other format discrepencies. I am so-far aware of the above)
goal
It would be helpful if the output of cast ad will marry with the input of cast call, so the former could more readily be piped into the latter.
Thanks.
Additional context
$ cast --version
cast 0.2.0 (a0a0020 2024-08-12T00:24:56.205249700Z)
Could you please share the commands with actual vs expected output?
@klkvr
$ SIG=<some function sig>
$ CONTRACT=<contract addr>
$ D=<raw call input>
Decode the input:
$ OUT=$(cast ad -i $SIG $D)
$ echo $OUT
0x1a4429df88017079d76311925d4A851302588401 10 (1720468176050 [1.72e12], 1720554576 [1.72e9], (0x9A19cf86Ecf1253F8916F9176Ee035DED8812c6A, 0xB8E9F649De42eDF145A8cD61dB7aF405DBB5c025, 0x36372b0700000000000000000000000000000000000000000000000000000000, 0, 2), (0x1a4429df88017079d76311925d4A851302588401, 0x0b315102f3191181f29638DA2B82323b14dE8Bff, 0x36372b0700000000000000000000000000000000000000000000000000000000, 0, 100), 0x0000000000000000000000000000000000000000, 0, 28, 0x29705578a3998f324a94a58daa107102b5f7952728341ff3c1901627b919a078, 0x6ba827ba79acb4c930dc080402ad9e9612bf95fbb63804e841abd3e97c247177)
Note that uint256s (e.g. 1720468176050) are followed-up with their respective sci representation, in square brackets, and 0x36372b0700000000000000000000000000000000000000000000000000000000 which are 4bytes values, with right zero-padding.
Break-up the arg list:
$ ARG1=$(echo $OUT|awk '{print $1}')
$ ARG2=$(echo $OUT|awk '{print $2}')
$ ARG3=$(echo $OUT|awk '{$1=""; $2=""; sub(/^ */, "");print $0}')
$ echo $ARG1 $ARG2 $ARG3
0x1a4429df88017079d76311925d4A851302588401 10 (1720468176050 [1.72e12], 1720554576 [1.72e9], (0x9A19cf86Ecf1253F8916F9176Ee035DED8812c6A, 0xB8E9F649De42eDF145A8cD61dB7aF405DBB5c025, 0x36372b0700000000000000000000000000000000000000000000000000000000, 0, 2), (0x1a4429df88017079d76311925d4A851302588401, 0x0b315102f3191181f29638DA2B82323b14dE8Bff, 0x36372b0700000000000000000000000000000000000000000000000000000000, 0, 100), 0x0000000000000000000000000000000000000000, 0, 28, 0x29705578a3998f324a94a58daa107102b5f7952728341ff3c1901627b919a078, 0x6ba827ba79acb4c930dc080402ad9e9612bf95fbb63804e841abd3e97c247177)
1st try:
$ cast call --trace $CONTRACT $SIG $ARG1 $ARG2 $ARG3
Error:
parser error:
(1720468176050
^
expected `,`
Seems it's the whitespace in ARG3. Remove:
$ ARG3_NO_SPACE=$(echo $ARG3|tr -d ' ')
$ cast call --trace $CONTRACT $SIG $ARG1 $ARG2 $ARG3_NO_SPACE
Error:
parser error:
(1720468176050[1.72e12],1720554576[1.72e9],(0x9A19cf86Ecf1253F8916F9176Ee035DED8812c6A,0xB8E9F649De42eDF145A8cD61dB7aF405DBB5c025,0x36372b0700000000000000000000000000000000000000000000000000000000,0,2),(0x1a4429df88017079d76311925d4A851302588401,0x0b315102f3191181f29638DA2B82323b14dE8Bff,0x36372b0700000000000000000000000000000000000000000000000000000000,0,100),0x0000000000000000000000000000000000000000,0,28,0x29705578a3998f324a94a58daa107102b5f7952728341ff3c1901627b919a078,0x6ba827ba79acb4c930dc080402ad9e9612bf95fbb63804e841abd3e97c247177)
^
expected `,`
Now it's the bracketed bits. Remove:
$ ARG3_NO_SCI=$(echo $ARG3_NO_SPACE|sed 's/\[[^]]*\]//g')
$ cast call --trace $CONTRACT $SIG $ARG1 $ARG2 $ARG3_NO_SCI
Error:
parser error:
(1720468176050,1720554576,(0x9A19cf86Ecf1253F8916F9176Ee035DED8812c6A,0xB8E9F649De42eDF145A8cD61dB7aF405DBB5c025,0x36372b0700000000000000000000000000000000000000000000000000000000,0,2),(0x1a4429df88017079d76311925d4A851302588401,0x0b315102f3191181f29638DA2B82323b14dE8Bff,0x36372b0700000000000000000000000000000000000000000000000000000000,0,100),0x0000000000000000000000000000000000000000,0,28,0x29705578a3998f324a94a58daa107102b5f7952728341ff3c1901627b919a078,0x6ba827ba79acb4c930dc080402ad9e9612bf95fbb63804e841abd3e97c247177)
^
Invalid string length
Now it looks-like it's the right zero padding on the bytes4. Truncate:
$ ARG3_NO_ZP=$(echo $ARG3_NO_SCI|sed 's/\(0x36372b07\)0\+/\1/g')
$ cast call --trace $CONTRACT $SIG $ARG1 $ARG2 $ARG3_NO_ZP > /dev/null;echo $?
0
call succeeds 👍🏼
Hey @fauxbytes! Thanks for showing interest. We've created an application for you to contribute to Foundry. Go check it out on OnlyDust!
Completed in #8687