-
Notifications
You must be signed in to change notification settings - Fork 683
Block difficulty is always '0' (zero) #662
Comments
Thanks for opening this issue. Are you using forking? |
Tried with and without forking - neither makes a difference - difficulty is still at 0. |
Without forking Setting When setting ganache to have a non-zero blocktime, you could make the argument that we should calculate difficulty and mixhash... but what values do we put? I'm definitely open to a other ideas, so please feel free to give arguments for why we should change. |
When forking - it doesn't retain the original forked values - just resets both The general logic about it being 0 as the blocks are instantaneous is quite solid. Although some projects (like Hardhat) use difficulty 1 for that (so the totalDifficulty keeps increasing). I don't know which logic is better. The reason why we need this on a synthetic developer chain - we're currently developing some intricate contracts that rely on blocks difficulties to make decisions (they values are passed with block header RLP's, decoded, and verified, as EVM cannot access them directly). But there's no way to fully test these contracts currently, except maybe on real networks with real mining - and that's also not quite good for testing - as we cannot really affect difficulty to test different values. So currently we're designing some hacks and mocks, but it would be nicer if contract really tested the values from the chain. So I was thinking about several solutions to this:
Or can be a mix of the above. |
Ah, thanks for the use-case example. Also, looks like there are two bugs in forking:
As for your use-case example, i'll talk to the team internally and see what we can come up with! |
#771 addresses this issue. |
merged! |
Expected Behavior
Hardhat (on the left) has
difficulty
andtotalDifficulty
values setCurrent Behavior
Ganache (on the right) has both
difficulty
andtotalDifficulty
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 ethereumjs/ethereumjs-monorepo#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).The text was updated successfully, but these errors were encountered: