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(forge script): add --json output support #10019

Open
2 tasks done
Tracked by #8794
mortimr opened this issue Mar 6, 2025 · 2 comments · May be fixed by #10109
Open
2 tasks done
Tracked by #8794

feat(forge script): add --json output support #10019

mortimr opened this issue Mar 6, 2025 · 2 comments · May be fixed by #10109
Labels
C-forge Command: forge Cmd-forge-script Command: forge script T-feature Type: feature

Comments

@mortimr
Copy link

mortimr commented Mar 6, 2025

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge Version: 1.0.0-stable Commit SHA: e144b82 Build Timestamp: 2025-02-13T20:02:34.979686000Z (1739476954) Build Profile: maxperf

What version of Foundryup are you on?

foundryup: 1.0.1

What command(s) is the bug in?

forge script

Operating System

macOS (Apple Silicon)

Describe the bug

Hey !

I'm currently running forge script programmatically and found out about the --json flag which is perfect for my use case where I'd need to retrieve the traces. Unfortunately it seems there is an issue with the decoded data payload in the traces.
When running the script on a fork, it seems that the complete execution traces in the json format lack all the decoding data. What hints as this being a bug is that the second payload in the output, the one containing the simulated on-chain traces section, actually has the decoded data, for a call identical to the one made in the simulation traces.

Here's the output without the --json flag (don't mind the weird input data, it's only for testing purposes)

No files changed, compilation skipped
Traces:
  [11754] MyScript::run([0x9A6034c84cd431409Ac1a35278c7Da36FfDa53E5], Value({ val: 1234, for_fun: [0x9A6034c84cd431409Ac1a35278c7Da36FfDa53E5, 0x9A6034c84cd431409Ac1a35278c7Da36FfDa53E5, 0x9A6034c84cd431409Ac1a35278c7Da36FfDa53E5] }), [0x9A6034c84cd431409Ac1a35278c7Da36FfDa53E5, 0x9A6034c84cd431409Ac1a35278c7Da36FfDa53E5, 0x9A6034c84cd431409Ac1a35278c7Da36FfDa53E5], "omg", 57896044618658097711785492504343953926634992332820282019728792003956564819967 [5.789e76])
    ├─ [0] VM::startBroadcast()
    │   └─ ← [Return]
    ├─ [0] another_one::test()
    │   └─ ← [Stop]
    ├─ [0] VM::stopBroadcast()
    │   └─ ← [Return]
    └─ ← [Stop]


Script ran successfully.

## Setting up 1 EVM.
==========================
Simulated On-chain Traces:

  [0] another_one::test()
    └─ ← [Stop]

Warning: Script contains a transaction to 0x9A6034c84cd431409Ac1a35278c7Da36FfDa53E5 which does not contain any code.

==========================

Chain 1

Estimated gas price: 1.381970521 gwei

Estimated total gas used for script: 29094

Estimated amount required: 0.000040207050337974 ETH

==========================

=== Transactions that will be broadcast ===


Chain 1

### Transaction 1 ###

accessList           []
chainId              1
gasLimit             29094
gasPrice
input                0xf8a8fd6d
maxFeePerBlobGas
maxFeePerGas
maxPriorityFeePerGas
nonce                1
to                   0x9A6034c84cd431409Ac1a35278c7Da36FfDa53E5
type                 0
value                0


SIMULATION COMPLETE. To broadcast these transactions, add --broadcast and wallet configuration(s) to the previous command. See forge script --help for more.

Transactions saved to: 
.../broadcast/MyScript.s.sol/1/dry-run/run-latest.json

Sensitive values saved to: 
.../cache/MyScript.s.sol/1/dry-run/run-latest.json

Here we can see that the test() call gets properly decoded (even the VM call is)

Now here are the two json payloads I get with the --json flag
First, the complete simulation traces, including script deployment

{
   "logs":[
      
   ],
   "returns":{
      
   },
   "success":true,
   "raw_logs":[
      
   ],
   "traces":[
      [
         "Deployment",
         {
            "arena":[
               {
                  "parent":null,
                  "children":[
                     
                  ],
                  "idx":0,
                  "trace":{
                     "depth":0,
                     "success":true,
                     "caller":"0x1804c8ab1f12e6bbf3894d4083f33e07309d1f38",
                     "address":"0x5b73c5498c1e3b4dba84de0f1833c4a029d90519",
                     "maybe_precompile":false,
                     "selfdestruct_address":null,
                     "selfdestruct_refund_target":null,
                     "selfdestruct_transferred_value":null,
                     "kind":"CREATE",
                     "value":"0x0",
                     "data":"0x60806040526001600c5f6101000a81548160ff0219169083151502179055506001600c60026101000a81548160ff0219169083151502179055503480156043575f80fd5b5061085a806100515f395ff3fe608060405234801561000f575f80fd5b5060043610610034575f3560e01c8063901ff56b14610038578063f8ccbf4714610054575b5f80fd5b610052600480360381019061004d9190610691565b610072565b005b61005c61028e565b6040516100699190610776565b60405180910390f35b7f885cb69240a935d632d79c317109709ecfa91a80626ff3989d68f67f5b1dd12d5f1c73ffffffffffffffffffffffffffffffffffffffff16637fb5297f6040518163ffffffff1660e01b81526004015f604051808303815f87803b1580156100d9575f80fd5b505af11580156100eb573d5f803e3d5ffd5b505050505f5b85518110156102095785818151811061010d5761010c61078f565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff166040516024016040516020818303038152906040527ff8a8fd6d000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516101bb919061080e565b5f604051808303815f865af19150503d805f81146101f4576040519150601f19603f3d011682016040523d82523d5f602084013e6101f9565b606091505b50505080806001019150506100f1565b507f885cb69240a935d632d79c317109709ecfa91a80626ff3989d68f67f5b1dd12d5f1c73ffffffffffffffffffffffffffffffffffffffff166376eadd366040518163ffffffff1660e01b81526004015f604051808303815f87803b158015610271575f80fd5b505af1158015610283573d5f803e3d5ffd5b505050505050505050565b600c60029054906101000a900460ff1681565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6102fc826102b6565b810181811067ffffffffffffffff8211171561031b5761031a6102c6565b5b80604052505050565b5f61032d6102a1565b905061033982826102f3565b919050565b5f67ffffffffffffffff821115610358576103576102c6565b5b602082029050602081019050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6103968261036d565b9050919050565b6103a68161038c565b81146103b0575f80fd5b50565b5f813590506103c18161039d565b92915050565b5f6103d96103d48461033e565b610324565b905080838252602082019050602084028301858111156103fc576103fb610369565b5b835b81811015610425578061041188826103b3565b8452602084019350506020810190506103fe565b5050509392505050565b5f82601f830112610443576104426102b2565b5b81356104538482602086016103c7565b91505092915050565b5f80fd5b5f80fd5b5f819050919050565b61047681610464565b8114610480575f80fd5b50565b5f813590506104918161046d565b92915050565b5f604082840312156104ac576104ab61045c565b5b6104b66040610324565b90505f6104c584828501610483565b5f83015250602082013567ffffffffffffffff8111156104e8576104e7610460565b5b6104f48482850161042f565b60208301525092915050565b5f67ffffffffffffffff82111561051a576105196102c6565b5b602082029050919050565b5f61053761053284610500565b610324565b9050806020840283018581111561055157610550610369565b5b835b8181101561057a578061056688826103b3565b845260208401935050602081019050610553565b5050509392505050565b5f82601f830112610598576105976102b2565b5b60036105a5848285610525565b91505092915050565b5f80fd5b5f67ffffffffffffffff8211156105cc576105cb6102c6565b5b6105d5826102b6565b9050602081019050919050565b828183375f83830152505050565b5f6106026105fd846105b2565b610324565b90508281526020810184848401111561061e5761061d6105ae565b5b6106298482856105e2565b509392505050565b5f82601f830112610645576106446102b2565b5b81356106558482602086016105f0565b91505092915050565b5f819050919050565b6106708161065e565b811461067a575f80fd5b50565b5f8135905061068b81610667565b92915050565b5f805f805f60e086880312156106aa576106a96102aa565b5b5f86013567ffffffffffffffff8111156106c7576106c66102ae565b5b6106d38882890161042f565b955050602086013567ffffffffffffffff8111156106f4576106f36102ae565b5b61070088828901610497565b945050604061071188828901610584565b93505060a086013567ffffffffffffffff811115610732576107316102ae565b5b61073e88828901610631565b92505060c061074f8882890161067d565b9150509295509295909350565b5f8115159050919050565b6107708161075c565b82525050565b5f6020820190506107895f830184610767565b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f81519050919050565b5f81905092915050565b8281835e5f83830152505050565b5f6107e8826107bc565b6107f281856107c6565b93506108028185602086016107d0565b80840191505092915050565b5f61081982846107de565b91508190509291505056fea264697066735822122014d58565131099eb57e03fade8712f269b5a39322365f9f39ed9794dd8860b6364736f6c634300081a0033",
                     "output":"0x608060405234801561000f575f80fd5b5060043610610034575f3560e01c8063901ff56b14610038578063f8ccbf4714610054575b5f80fd5b610052600480360381019061004d9190610691565b610072565b005b61005c61028e565b6040516100699190610776565b60405180910390f35b7f885cb69240a935d632d79c317109709ecfa91a80626ff3989d68f67f5b1dd12d5f1c73ffffffffffffffffffffffffffffffffffffffff16637fb5297f6040518163ffffffff1660e01b81526004015f604051808303815f87803b1580156100d9575f80fd5b505af11580156100eb573d5f803e3d5ffd5b505050505f5b85518110156102095785818151811061010d5761010c61078f565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff166040516024016040516020818303038152906040527ff8a8fd6d000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516101bb919061080e565b5f604051808303815f865af19150503d805f81146101f4576040519150601f19603f3d011682016040523d82523d5f602084013e6101f9565b606091505b50505080806001019150506100f1565b507f885cb69240a935d632d79c317109709ecfa91a80626ff3989d68f67f5b1dd12d5f1c73ffffffffffffffffffffffffffffffffffffffff166376eadd366040518163ffffffff1660e01b81526004015f604051808303815f87803b158015610271575f80fd5b505af1158015610283573d5f803e3d5ffd5b505050505050505050565b600c60029054906101000a900460ff1681565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6102fc826102b6565b810181811067ffffffffffffffff8211171561031b5761031a6102c6565b5b80604052505050565b5f61032d6102a1565b905061033982826102f3565b919050565b5f67ffffffffffffffff821115610358576103576102c6565b5b602082029050602081019050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6103968261036d565b9050919050565b6103a68161038c565b81146103b0575f80fd5b50565b5f813590506103c18161039d565b92915050565b5f6103d96103d48461033e565b610324565b905080838252602082019050602084028301858111156103fc576103fb610369565b5b835b81811015610425578061041188826103b3565b8452602084019350506020810190506103fe565b5050509392505050565b5f82601f830112610443576104426102b2565b5b81356104538482602086016103c7565b91505092915050565b5f80fd5b5f80fd5b5f819050919050565b61047681610464565b8114610480575f80fd5b50565b5f813590506104918161046d565b92915050565b5f604082840312156104ac576104ab61045c565b5b6104b66040610324565b90505f6104c584828501610483565b5f83015250602082013567ffffffffffffffff8111156104e8576104e7610460565b5b6104f48482850161042f565b60208301525092915050565b5f67ffffffffffffffff82111561051a576105196102c6565b5b602082029050919050565b5f61053761053284610500565b610324565b9050806020840283018581111561055157610550610369565b5b835b8181101561057a578061056688826103b3565b845260208401935050602081019050610553565b5050509392505050565b5f82601f830112610598576105976102b2565b5b60036105a5848285610525565b91505092915050565b5f80fd5b5f67ffffffffffffffff8211156105cc576105cb6102c6565b5b6105d5826102b6565b9050602081019050919050565b828183375f83830152505050565b5f6106026105fd846105b2565b610324565b90508281526020810184848401111561061e5761061d6105ae565b5b6106298482856105e2565b509392505050565b5f82601f830112610645576106446102b2565b5b81356106558482602086016105f0565b91505092915050565b5f819050919050565b6106708161065e565b811461067a575f80fd5b50565b5f8135905061068b81610667565b92915050565b5f805f805f60e086880312156106aa576106a96102aa565b5b5f86013567ffffffffffffffff8111156106c7576106c66102ae565b5b6106d38882890161042f565b955050602086013567ffffffffffffffff8111156106f4576106f36102ae565b5b61070088828901610497565b945050604061071188828901610584565b93505060a086013567ffffffffffffffff811115610732576107316102ae565b5b61073e88828901610631565b92505060c061074f8882890161067d565b9150509295509295909350565b5f8115159050919050565b6107708161075c565b82525050565b5f6020820190506107895f830184610767565b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f81519050919050565b5f81905092915050565b8281835e5f83830152505050565b5f6107e8826107bc565b6107f281856107c6565b93506108028185602086016107d0565b80840191505092915050565b5f61081982846107de565b91508190509291505056fea264697066735822122014d58565131099eb57e03fade8712f269b5a39322365f9f39ed9794dd8860b6364736f6c634300081a0033",
                     "gas_used":450542,
                     "gas_limit":1073654440,
                     "status":"Return",
                     "steps":[
                        
                     ],
                     "decoded":{
                        "label":null,
                        "return_data":null,
                        "call_data":null
                     }
                  },
                  "logs":[
                     
                  ],
                  "ordering":[
                     
                  ]
               }
            ]
         }
      ],
      [
         "Execution",
         {
            "arena":[
               {
                  "parent":null,
                  "children":[
                     1,
                     2,
                     3
                  ],
                  "idx":0,
                  "trace":{
                     "depth":0,
                     "success":true,
                     "caller":"0xc1caf43fb9ac723fef07ea94a1c423880cdf5301",
                     "address":"0x5b73c5498c1e3b4dba84de0f1833c4a029d90519",
                     "maybe_precompile":null,
                     "selfdestruct_address":null,
                     "selfdestruct_refund_target":null,
                     "selfdestruct_transferred_value":null,
                     "kind":"CALL",
                     "value":"0x0",
                     "data":"0x901ff56b00000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001200000000000000000000000009a6034c84cd431409ac1a35278c7da36ffda53e50000000000000000000000009a6034c84cd431409ac1a35278c7da36ffda53e50000000000000000000000009a6034c84cd431409ac1a35278c7da36ffda53e500000000000000000000000000000000000000000000000000000000000001e07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000010000000000000000000000009a6034c84cd431409ac1a35278c7da36ffda53e500000000000000000000000000000000000000000000000000000000000004d2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000030000000000000000000000009a6034c84cd431409ac1a35278c7da36ffda53e50000000000000000000000009a6034c84cd431409ac1a35278c7da36ffda53e50000000000000000000000009a6034c84cd431409ac1a35278c7da36ffda53e500000000000000000000000000000000000000000000000000000000000000036f6d670000000000000000000000000000000000000000000000000000000000",
                     "output":"0x",
                     "gas_used":11754,
                     "gas_limit":1073716352,
                     "status":"Stop",
                     "steps":[
                        
                     ],
                     "decoded":{
                        "label":null,
                        "return_data":null,
                        "call_data":null
                     }
                  },
                  "logs":[
                     
                  ],
                  "ordering":[
                     {
                        "Call":0
                     },
                     {
                        "Call":1
                     },
                     {
                        "Call":2
                     }
                  ]
               },
               {
                  "parent":0,
                  "children":[
                     
                  ],
                  "idx":1,
                  "trace":{
                     "depth":1,
                     "success":true,
                     "caller":"0x5b73c5498c1e3b4dba84de0f1833c4a029d90519",
                     "address":"0x7109709ecfa91a80626ff3989d68f67f5b1dd12d",
                     "maybe_precompile":null,
                     "selfdestruct_address":null,
                     "selfdestruct_refund_target":null,
                     "selfdestruct_transferred_value":null,
                     "kind":"CALL",
                     "value":"0x0",
                     "data":"0x7fb5297f",
                     "output":"0x",
                     "gas_used":0,
                     "gas_limit":1056931530,
                     "status":"Return",
                     "steps":[
                        
                     ],
                     "decoded":{
                        "label":null,
                        "return_data":null,
                        "call_data":null
                     }
                  },
                  "logs":[
                     
                  ],
                  "ordering":[
                     
                  ]
               },
               {
                  "parent":0,
                  "children":[
                     
                  ],
                  "idx":2,
                  "trace":{
                     "depth":1,
                     "success":true,
                     "caller":"0x5b73c5498c1e3b4dba84de0f1833c4a029d90519",
                     "address":"0x9a6034c84cd431409ac1a35278c7da36ffda53e5",
                     "maybe_precompile":null,
                     "selfdestruct_address":null,
                     "selfdestruct_refund_target":null,
                     "selfdestruct_transferred_value":null,
                     "kind":"CALL",
                     "value":"0x0",
                     "data":"0xf8a8fd6d",
                     "output":"0x",
                     "gas_used":0,
                     "gas_limit":1056928423,
                     "status":"Stop",
                     "steps":[
                        
                     ],
                     "decoded":{
                        "label":null,
                        "return_data":null,
                        "call_data":null
                     }
                  },
                  "logs":[
                     
                  ],
                  "ordering":[
                     
                  ]
               },
               {
                  "parent":0,
                  "children":[
                     
                  ],
                  "idx":3,
                  "trace":{
                     "depth":1,
                     "success":true,
                     "caller":"0x5b73c5498c1e3b4dba84de0f1833c4a029d90519",
                     "address":"0x7109709ecfa91a80626ff3989d68f67f5b1dd12d",
                     "maybe_precompile":null,
                     "selfdestruct_address":null,
                     "selfdestruct_refund_target":null,
                     "selfdestruct_transferred_value":null,
                     "kind":"CALL",
                     "value":"0x0",
                     "data":"0x76eadd36",
                     "output":"0x",
                     "gas_used":0,
                     "gas_limit":1056928013,
                     "status":"Return",
                     "steps":[
                        
                     ],
                     "decoded":{
                        "label":null,
                        "return_data":null,
                        "call_data":null
                     }
                  },
                  "logs":[
                     
                  ],
                  "ordering":[
                     
                  ]
               }
            ]
         }
      ]
   ],
   "gas_used":37226,
   "labeled_addresses":{
...
   },
   "returned":"0x",
   "address":null
}

And here is the second payload, with only broadcasted calls. Here we can see that the decoded data section includes the label and call info.

{
   "arena":[
      {
         "parent":null,
         "children":[
            
         ],
         "idx":0,
         "trace":{
            "depth":0,
            "success":true,
            "caller":"0xc1caf43fb9ac723fef07ea94a1c423880cdf5301",
            "address":"0x9a6034c84cd431409ac1a35278c7da36ffda53e5",
            "maybe_precompile":null,
            "selfdestruct_address":null,
            "selfdestruct_refund_target":null,
            "selfdestruct_transferred_value":null,
            "kind":"CALL",
            "value":"0x0",
            "data":"0xf8a8fd6d",
            "output":"0x",
            "gas_used":0,
            "gas_limit":1073720760,
            "status":"Stop",
            "steps":[
               
            ],
            "decoded":{
               "label":"another_one",
               "return_data":null,
               "call_data":{
                  "signature":"test()",
                  "args":[
                     
                  ]
               }
            }
         },
         "logs":[
            
         ],
         "ordering":[
            
         ]
      }
   ]
}

So I'm guessing there is an issue with the forwarded decoded data for the first payload.

@mortimr mortimr added T-bug Type: bug T-needs-triage Type: this issue needs to be labelled labels Mar 6, 2025
@github-project-automation github-project-automation bot moved this to Todo in Foundry Mar 6, 2025
@zerosnacks zerosnacks changed the title Empty decoded section in --json output feat(forge script): add --json output support Mar 6, 2025
@zerosnacks
Copy link
Member

Hi @mortimr thanks for raising this, there are some parts of Foundry that do not fully support the --json flag due to mixed output modes. I'll mark this as a feature request.

@zerosnacks zerosnacks added C-forge Command: forge Cmd-forge-script Command: forge script T-feature Type: feature and removed T-bug Type: bug T-needs-triage Type: this issue needs to be labelled labels Mar 6, 2025
@0xscharki
Copy link

Can I attempt this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-script Command: forge script T-feature Type: feature
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

3 participants