Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: assign default difficulty to zero for chain without ethash #31067

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fjl
Copy link
Contributor

@fjl fjl commented Jan 23, 2025

I hit this case while trying something with the simulated backend. The EVM only enables instruction set forks after the merge when 'Random' is set. In the simulated backend, the random value will be set via the engine API for all blocks after genesis. But for the genesis block itself, the random value will not be assigned in the vm.BlockContext because the genesis has a non-zero difficulty. For my case, this meant that estimateGas did not work for the first transaction sent on the simulated chain, since the contract contained a PUSH0 instruction.

This could also be fixed by explicitly configuring a zero difficulty in the simulated backend. However, I think that zero difficulty is a better default these days.

I hit this case while trying something with the simulated backend. The EVM only enables
instruction set forks after the merge when 'Random' is set. In the simulated backend, the
random value will be set via the engine API for all blocks after genesis. But for the
genesis block itself, the random value will not be assigned in the vm.BlockContext because
the genesis has a non-zero difficulty. For my case, this meant that estimateGas did not
work for the first transaction sent on the simulated chain, since the contract contained a
PUSH0 instruction.

This could also be fixed by explicitly configuring a zero difficulty in the simulated
backend. However, I think that zero difficulty is a better default these days.
@rjl493456442
Copy link
Member

CI is failing

@@ -459,8 +459,12 @@ func (g *Genesis) toBlockWithRoot(root common.Hash) *types.Block {
if g.GasLimit == 0 {
head.GasLimit = params.GenesisGasLimit
}
if g.Difficulty == nil && g.Mixhash == (common.Hash{}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QQ, Why the g.MixHash == (common.Hash{}) is a condition for setting the genesis difficulty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get it either. This code is very old.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@fjl fjl Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be related with the idea of how the header MixDigest is used. After the merge, this field was repurposed for the random value. What @MariusVanDerWijden may have been thinking is: "if Mixhash is set in genesis, it means the genesis block is supposed to have a random value (signaling the merge), and thus difficulty will be set to zero."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants