Skip to content

The gasUsed of each EVM call is not clear. #28074

@xuht724

Description

@xuht724

I am analysing the gas used distribution in a transaction. Here is a trace example and my analysis result. I am curious about why the calculated remaining gas is larger than the gas after the final call. (40554 > 36662)
Does any gas refund that I do not consider. How can I correctly get the gas used in each evm call.

Trx Hash 0xb06aca08b58e7b89c47aa33fd250560d3f2d8790902af2895d677c07111f40ca
trx gas 135181 trx used 94627
Transaction remaining gas 40554
accessList gas cost 33800
calldata_gascost 432
begin gas 79949

EVM Call Gas Distribution 
0x6b75d8af000000e20b7a7ddf000ba900b4009a80 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 transferFrom
Begin gas 78436 Call gas cost 8732 After Call Gas 69704
0x6b75d8af000000e20b7a7ddf000ba900b4009a80 0x3a22710dbd18ddcfe64e28ed5a97fa4774fd2c3d v2swap
Begin gas 69682 Call gas cost 33020 After Call Gas 36662

{
    "from": "0xae2fc483527b8ef99eb5d9b44875f005ba1fae13",
    "gas": "0x1384d",
    "gasUsed": "0x171a3",
    "to": "0x6b75d8af000000e20b7a7ddf000ba900b4009a80",
    "input": "0x802f183a22710dbd18ddcfe64e28ed5a97fa4774fd2c3d480d4c32",
    "calls": [
        {
            "from": "0x6b75d8af000000e20b7a7ddf000ba900b4009a80",
            "gas": "0x13264",
            "gasUsed": "0x221c",
            "to": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
            "input": "0x23b872dd0000000000000000000000006b75d8af000000e20b7a7ddf000ba900b4009a800000000000000000000000003a22710dbd18ddcfe64e28ed5a97fa4774fd2c3d0000000000000000000000000000000000000000000000000ab200a500000000",
            "output": "0x0000000000000000000000000000000000000000000000000000000000000001",
            "value": "0x0",
            "type": "CALL"
        },
        {
            "from": "0x6b75d8af000000e20b7a7ddf000ba900b4009a80",
            "gas": "0x11032",
            "gasUsed": "0x80fc",
            "to": "0x3a22710dbd18ddcfe64e28ed5a97fa4774fd2c3d",
            "input": "0x022c0d9f0000000000000000000000000000000000000000480d4c32000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006b75d8af000000e20b7a7ddf000ba900b4009a8000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000",
            "calls": [
                {
                    "from": "0x3a22710dbd18ddcfe64e28ed5a97fa4774fd2c3d",
                    "gas": "0xf933",
                    "gasUsed": "0x28d0",
                    "to": "0x27f103f86070cc639fef262787a16887d22d8415",
                    "input": "0xa9059cbb0000000000000000000000006b75d8af000000e20b7a7ddf000ba900b4009a800000000000000000000000000000000000000000480d4c320000000000000000",
                    "output": "0x0000000000000000000000000000000000000000000000000000000000000001",
                    "value": "0x0",
                    "type": "CALL"
                },
                {
                    "from": "0x3a22710dbd18ddcfe64e28ed5a97fa4774fd2c3d",
                    "gas": "0xce99",
                    "gasUsed": "0x2cb",
                    "to": "0x27f103f86070cc639fef262787a16887d22d8415",
                    "input": "0x70a082310000000000000000000000003a22710dbd18ddcfe64e28ed5a97fa4774fd2c3d",
                    "output": "0x000000000000000000000000000000000000000b38821d736fa08423600f081b",
                    "type": "STATICCALL"
                },
                {
                    "from": "0x3a22710dbd18ddcfe64e28ed5a97fa4774fd2c3d",
                    "gas": "0xca44",
                    "gasUsed": "0x216",
                    "to": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
                    "input": "0x70a082310000000000000000000000003a22710dbd18ddcfe64e28ed5a97fa4774fd2c3d",
                    "output": "0x000000000000000000000000000000000000000000000001b3cefd15d747e50e",
                    "type": "STATICCALL"
                }
            ],
            "value": "0x0",
            "type": "CALL"
        }
    ],
    "value": "0xab200a5",
    "type": "CALL"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions