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.

Block difficulty is always '0' (zero)

See original GitHub issue

image

Expected Behavior

Hardhat (on the left) has difficulty and totalDifficulty values set

Current Behavior

Ganache (on the right) has both difficulty and totalDifficulty values equal to zero.

Possible Solution

Both projects use ethereumjs-vm version v4.2.0.

I assume the difference happens during block creation (as far as I remember Hardhat set difficulty based on the latest block):

https://github.com/nomiclabs/hardhat/blob/6c3cdb7445c3b2960ed6bfce50d09bc11338479e/packages/hardhat-core/src/internal/hardhat-network/provider/node.ts#L1040

Ganache doesn’t seem to have any difficulty-related header assignment:

https://github.com/trufflesuite/ganache-core/blob/1177fe8a2711066a1b082b15d22585158001e80d/lib/blockchain_double.js#L600

P.S. Btw, also https://github.com/ethereumjs/ethereumjs-vm/pull/929 was merged 5 days ago - introducing a new way of setting a difficulty in ethereumjs-vm (but Hardhat was setting difficulty before this release).

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
eggplantzzzcommented, Feb 5, 2021
1reaction
davidmurdochcommented, Nov 12, 2020

Ah, thanks for the use-case example.

Also, looks like there are two bugs in forking:

  1. On blocks fetched from the original chain we are setting difficulty to totalDifficulty.
  2. Even though we’ve intended for difficulty to be 0, we don’t keep the totalDifficulty around, as we should.

As for your use-case example, i’ll talk to the team internally and see what we can come up with!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mining Difficulty and Leading Zeros - Bitcoin Stack Exchange
The difficulty adjustment is such that, if the average time to mine a block is greater than 10 minutes, then the difficulty will...
Read more >
Difficulty - Bitcoin Wiki
The Bitcoin network has a global block difficulty. ... bits are zero and the rest are one (this is known as "pool difficulty"...
Read more >
Bitcoin Mining Difficulty: Everything You Need to Know
While a 10-minute block time is the goal, the mining difficulty cannot be altered above or below four times the current difficulty level....
Read more >
The mining difficulty represents the amount of leading zeros ...
The mining difficulty represents the amount of leading zeroes” is an oversimplification that people sometimes use (me included) when they don't want to...
Read more >
Mining Difficulty - Simply Explained - YouTube
Mining Bitcoin or Ethereum is a hard task for your computer. But why? And what does the difficulty have to do with the...
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