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

fix(core/evm): set difficulty post shanghai to 0 #832

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

Conversation

darioush
Copy link
Collaborator

@darioush darioush commented Feb 25, 2025

Why this should be merged

Seems post merge difficulty is set to 0 not nil https://github.com/ava-labs/libevm/blob/main/core/evm.go#L71
If you copy a header with nil difficulty, you end up with a header with difficulty 0.
So seems we should fix this.

How this works

Changes nil to 0

How this was tested

CI

Need to be documented?

No

Need to update RELEASES.md?

No

@darioush darioush marked this pull request as ready for review February 25, 2025 04:18
@darioush darioush requested review from ceyonur and a team as code owners February 25, 2025 04:18
Copy link
Collaborator

@qdm12 qdm12 left a comment

Choose a reason for hiding this comment

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

Good catch to you! 💯
I noticed that was a bit odd, but I didn't think it through any further 😄 !

@darioush darioush requested a review from ARR4N February 25, 2025 16:03
@@ -65,7 +65,7 @@ func (hooks) OverrideNewEVMArgs(args *vm.NewEVMArgs) *vm.NewEVMArgs {
if rules.IsShanghai {
args.BlockContext.Random = new(common.Hash)
args.BlockContext.Random.SetBytes(args.BlockContext.Difficulty.Bytes())
args.BlockContext.Difficulty = nil
args.BlockContext.Difficulty = new(big.Int)
Copy link
Collaborator

Choose a reason for hiding this comment

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

aren't we expecting this to be 1 here?

Copy link
Collaborator Author

@darioush darioush Feb 26, 2025

Choose a reason for hiding this comment

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

in the header yes, but not in the block context, which is the handoff point to the EVM interpreter.
The interpreter will start using the "Random" opcode post shanghai, which will read the value of "Random"
The value of Difficulty will actually be unused (Which is how this was previously working), but I still figure it's better to set it the same way as upstream.

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.

4 participants