-
Notifications
You must be signed in to change notification settings - Fork 678
Ganache produces shifted or even negative gas costs in debug_traceTransaction #277
Comments
At first glance this looks like you may not be accounting for gas refunds. Check the transaction receipt for refunds and let me know if that makes up the difference. |
I don't have the gas refund field on a transaction receipt. {
"tx": "0xb96de1919cc8268432339972c840a6a4852ca46d80d26bb658b14a54481b2d2b",
"receipt": {
"transactionHash": "0xb96de1919cc8268432339972c840a6a4852ca46d80d26bb658b14a54481b2d2b",
"transactionIndex": 0,
"blockHash": "0x811b451ae66ef866ab750d07e3bec92b1d802b144c0fbad5b4525dd31b4e3e8b",
"blockNumber": 8,
"from": "0x165e8d458e567b0568d1600646a804ad856e67b9",
"to": "0x64fabd680c1f2f4bc0a12e5f51ee1f98eeae0baa",
"gasUsed": 39437,
"cumulativeGasUsed": *39437*,
"contractAddress": null,
"logs": [],
"status": true,
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"v": "0x1b",
"r": "0xebe9c6dfab9b6ef321ac62600f01055f807f7f889aa3c56e8297d08573fc4e80",
"s": "0x303804a3d55110afdb13ca4de12b50a45325ceb9d0812256a43cd9c527253b2a",
"rawLogs": []
},
"logs": []
} The whole gas that's in the trace is:
If you substract |
I've digged deeped into ganache trace and it seems like it's shifted. [
{
"gasCost": 24216,
"op": "PUSH1",
},
{
"gasCost": 3,
"op": "PUSH1",
},
{
"gasCost": 3,
"op": "MSTORE",
},
{
"gasCost": 12,
"op": "PUSH1",
},
{
"gasCost": 3,
"op": "CALLDATASIZE",
},
{
"gasCost": 2,
"op": "LT",
}, When in reality if I check here or in yellowpaper here are the costs: |
Thanks for this additional info, @LogvinovLeon! It's not immediately clear what's going wrong in the accounting in trace transaction. I suspect that because the EVM |
Good catch with the negative gas costs. It's worth noting that this one is immediately after the |
Ok, so part of that issue is my bad. Negative and shifted gas costs should not happen either way though. |
I'd like to inform you that shifting |
Expected Behavior
I expect the trace to contain all the gas used by the transaction assigned to opcodes.
Current Behavior
In reality, when I sum all the costs found in a trace I get much less than the gas found on a transaction receipt.
(The image is actually from geth and is here just for visual purposes)
Possible Solution
Investigate and either fix or explain why is it like that.
Steps to Reproduce (for bugs)
truffle
project from ametacoin
box.sendCoin
You don't need that exact box. Just any smart contract transaction. This is probably the simplest one.
You could probably also use remix.
Context
I'm building a profiler based on traces and I can only assign half of the gas to opcodes. I'd like to know where is the other half.
BTW, Geth has the same problem, so there is probably some fundamental misunderstanding on my side about how gas/traces work.
Your Environment
The text was updated successfully, but these errors were encountered: