openethereum / parity-ethereum

The fast, light, and robust client for Ethereum-like networks.
Other
6.83k stars 1.69k forks source link

gas and gasUsed values are incorrect in the results from trace_filter #2817

Closed bokkypoobah closed 8 years ago

bokkypoobah commented 8 years ago

I'm running Parity/v1.3.8-beta/x86_64-linux-gnu/rustc1.12.0 on Linux synced to the main ETH chain.

Using the following command:

curl localhost:8545 -X POST --header 'Content-type: application/json' --data '{"jsonrpc":"2.0", "method":"trace_filter", "params":[{"fromBlock": "2283397", "toBlock": "2283397", "toAddress": ["0xb284e6a25d0972f9a92fec45d2075067db2d49b0"]}], "id":1}' | python -m json.tool

I get the following results:

{
    "id": 1,
    "jsonrpc": "2.0",
    "result": [
        {
            "action": {
                "create": {
                    "from": "0x1d0fee96aa9750f87894b034d25e17edca8b76a3",
                    "gas": "0x052ae1",
                    "init": "0x6060...e056",
                    "value": "0x00"
                }
            },
            "blockHash": "0x15047ca658f995190ee06f013ad2c2c0a5a2179cb7ec81072e73770bdad78284",
            "blockNumber": "0x22d785",
            "result": {
                "create": {
                    "address": "0xb284e6a25d0972f9a92fec45d2075067db2d49b0",
                    "code": "0x6060...e056",
                    "gasUsed": "0x03a441"
                }
            },
            "subtraces": "0x00",
            "traceAddress": [],
            "transactionHash": "0x403b4bf619ab760a5d88a73a87fb12606f150328075d9795ef34f5157525b887",
            "transactionPosition": "0x01"
        }
    ]
}

So gas is 0x052ae1 (338657) and gasUsed is 0x03a441 (238657) according to Parity.

The gas and gasUsed results are different to geth's results:

> eth.getTransaction("0x403b4bf619ab760a5d88a73a87fb12606f150328075d9795ef34f5157525b887").gas
467645
> eth.getTransactionReceipt("0x403b4bf619ab760a5d88a73a87fb12606f150328075d9795ef34f5157525b887").gasUsed
367645

And they are different to etherscan.io's results:0x403b4bf619ab760a5d88a73a87fb12606f150328075d9795ef34f5157525b887: screen shot 2016-10-23 at 02 11 58

gavofyork commented 8 years ago

The different between Geth (which includes etherscan.io) and Parity is that Parity does not include the intrinsic transaction cost, i.e. the cost of including the transaction data in the block itself. This is because these trace entries are meant to give you information about the code execution environment which is common across all forms of contract-creation and message-call, regardless of whether they originated as a transaction or from a CALL or CREATE operation.

So to be clear, there are really three important values here:

From these three values, you can arrive at:

Note:

Parity provides you with three of these values (I assume transaction is equal to eth.getTransaction("0x403b4bf619ab760a5d88a73a87fb12606f150328075d9795ef34f5157525b887") and trace is the result of your curl query):

With these three values, you can derive the rest of the amounts, particularly those that Geth furnishes you with:

As an aside, since Geth provides you only with total_used and total_provided, you can only derive refund; you can not figure out the additional information intrinsic_used, interior_used or interior_provided. As such Parity is strictly more informative.

bokkypoobah commented 8 years ago

Thanks for the explanation @gavofyork