question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ganache produces shifted or even negative gas costs in debug_traceTransaction

See original GitHub issue

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.

screen shot 2019-01-17 at 5 48 31 pm (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)

  1. Create truffle project from a metacoin box.
  2. Run JS test that calls sendCoin
  3. Look at ganache logs to see the gas usage.
  4. Request the transaction trace and sum up gas costs of opcodes.

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

  • Version used: Latest and latest beta.
  • Environment name and version (e.g. PHP 5.4 on nginx 1.9.1):
  • Server type and version:
  • Operating System and version: Mac latest
  • Link to your project: https://0x.org

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

6reactions
LogvinovLeoncommented, Feb 26, 2019

I’d like to inform you that shifting gasCosts works. I’ve just done it on my side and now I’m able to reconstruct the whole gas use by a transaction and profile it. I will not close the issue because it should be fixed on your side.

2reactions
LogvinovLeoncommented, Jan 17, 2019

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: PUSH1 -> 3 MSTORE -> 3 * length CALLDATASIZE -> 2 *

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why gas prices are so high
Gas prices have more than doubled in two years, adding enormous costs for drivers. Here's what caused prices to soar.
Read more >
Why US gas prices are at a record and why they'll stay high ...
Numerous factors are combining to push gas prices up to a record. Gas hit $4.25 for a gallon of regular gas, according to...
Read more >
Fuel prices are a problem for business and consumers
Consumers are grappling with record high gas prices, but the surge is also hurting businesses.
Read more >
Why gas prices are so high, explained
Gasoline is the only product in modern-day America whose price is listed on giant signs almost everywhere you go. Most people, even if...
Read more >
Gasoline costs more these days, but price spikes have a ...
A driver makes his selection from various fuels priced over $6 at a ... Also, gas prices are posted all over town on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found