foundry icon indicating copy to clipboard operation
foundry copied to clipboard

bug(`anvil`): JSON-RPC `trace_transaction` `error` field is not set

Open michprev opened this issue 3 years ago • 4 comments

Component

Anvil

Describe the feature you would like

Looking at the output of the trace_transaction JSON-RPC method, I cannot see i proper way to distinguish between a reverted transaction (with optional revert reason data) and a successful transaction with return data. Would it be possible to add a boolean status field distinguishing between a failed and a successful transaction? The status can be queried using the eth_getTransactionReceipt request but that requires one more JSON-RPC method to be sent.

Additional context

No response

michprev avatar Oct 26 '22 11:10 michprev

there's the error field, but we currently don't set it, which is a bug.

mattsse avatar Oct 28 '22 15:10 mattsse

@mattsse any further progress on this? Is there any (sub)task I can help with?

This feature is quite important as it allows to:

  • detect created contracts,
  • detect self-destructed contracts,
  • print call trace with status (success/failure) for each trace, without the need of using debug_traceTransaction, which can be slow.

michprev avatar Mar 29 '23 13:03 michprev

I just dealt with recently on reth again and it turns out this step isn't actually correct:

https://github.com/foundry-rs/foundry/blob/7398b65e831f2339d1d0a0bb05ade799e4f9d01e/anvil/src/eth/backend/mem/storage.rs#L373-L373

result and error are mutually exclusive:

https://github.com/foundry-rs/foundry/blob/7398b65e831f2339d1d0a0bb05ade799e4f9d01e/anvil/src/eth/backend/mem/storage.rs#L391-L391

error needs to be set if the tx failed

mattsse avatar Mar 29 '23 13:03 mattsse

I think the result field makes sense in both cases when the tx fails and succeeds.

Currently, the result field contains gas_used, code and address sub-fields for create call traces and gas_used and output for non-create call traces.

  1. the output field is useful in case of a failed transaction because it contains the revert reason
  2. there is currently no way to receive the revert reason for create call traces

With trace_transaction it is currently not possible to get the Err selector and arguments.

contract Foo {
    error Err(string msg);

    constructor() public {
        revert Err("test");
    }
}

michprev avatar Mar 30 '23 15:03 michprev

@michprev could you please check if that's the same with latest anvil? This area of code was changed (migrated to alloy providers) and errors should be properly set in TransactionTrace.error field CC @mattsse

grandizzy avatar Oct 03 '24 06:10 grandizzy

I confirm this is no longer an issue, error field is set if tx reverted, e.g. for linea failed tx https://lineascan.build/tx/0x314bac8fe99200e5e0c928d9dd399091bb69ae774835272cb5d524d3711a9176 the error filed is populated as "error":"Reverted"

curl http://127.0.0.1:8545 \
-X POST -H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"trace_transaction","params": ["0x314bac8fe99200e5e0c928d9dd399091bb69ae774835272cb5d524d3711a9176"],"id":1}'

result

{"jsonrpc":"2.0","id":1,"result":[{"action":{"from":"0xe615e382a28e9fe71dc9d74793f714d617b3a081","callType":"call","gas":"0x3d9ba","input":"0xd4dfd6bc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000066a13592000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000415dcecf2a5f21907b0e2237a733b160187ebb402791c96deb5a68d0725687d3e35fe9050c37975c97e6cbe9cb2685ded3bc91f589b4826be0e6073a2e94f8f41f1b00000000000000000000000000000000000000000000000000000000000000","to":"0x3eb78e881b28b71329344df622ea3a682538ec6a","value":"0x0"},"blockHash":"0x560fe839afa43647aefa792d81f6581a6025d80b0086edf411b11e9f6bc9c4d4","blockNumber":7215240,"error":"Reverted","result":null,"subtraces":1,"traceAddress":[],"transactionHash":"0x314bac8fe99200e5e0c928d9dd399091bb69ae774835272cb5d524d3711a9176","transactionPosition":48,"type":"call"},{"action":{"from":"0x3eb78e881b28b71329344df622ea3a682538ec6a","callType":"delegatecall","gas":"0x3bfe4","input":"0xd4dfd6bc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000066a13592000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000415dcecf2a5f21907b0e2237a733b160187ebb402791c96deb5a68d0725687d3e35fe9050c37975c97e6cbe9cb2685ded3bc91f589b4826be0e6073a2e94f8f41f1b00000000000000000000000000000000000000000000000000000000000000","to":"0x38150d844143d0a9cde9633f117931250b49dd6b","value":"0x0"},"blockHash":"0x560fe839afa43647aefa792d81f6581a6025d80b0086edf411b11e9f6bc9c4d4","blockNumber":7215240,"error":"Reverted","result":null,"subtraces":0,"traceAddress":[0],"transactionHash":"0x314bac8fe99200e5e0c928d9dd399091bb69ae774835272cb5d524d3711a9176","transactionPosition":48,"type":"call"}]}

@michprev please reopen if you still see issues with. thank you!

grandizzy avatar Oct 16 '24 07:10 grandizzy