Skip to content

XDC Random Value#10803

Open
batrr wants to merge 1 commit intomasterfrom
feat/xdc-rng
Open

XDC Random Value#10803
batrr wants to merge 1 commit intomasterfrom
feat/xdc-rng

Conversation

@batrr
Copy link
Contributor

@batrr batrr commented Mar 12, 2026

XDC uses the block number as a random number, not the difficulty.

Changes

  • Add BlockExecutionContext.WithPrevRandao static factory for custom RNG injection
  • Override CreateBlockExecutionContext to pass xdc specific PREVRANDAO xdc

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

@github-actions
Copy link
Contributor

EVM Opcode Benchmark Diff

Aggregated runs: base=1, pr=1

No significant regressions or improvements detected.

@batrr batrr marked this pull request as ready for review March 12, 2026 10:40
@batrr batrr requested a review from Copilot March 12, 2026 10:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an extension point for customizing the EVM BlockExecutionContext per chain, and uses it to inject an XDC-specific PREVRANDAO value during block processing.

Changes:

  • Added BlockExecutionContext.WithPrevRandao(...) factory to allow custom PREVRANDAO injection.
  • Added BlockProcessor.CreateBlockExecutionContext(...) (virtual) and routed transaction execution through it.
  • Overrode CreateBlockExecutionContext in XdcBlockProcessor to provide an XDC-specific PREVRANDAO value derived from the block number.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/Nethermind/Nethermind.Xdc/XdcBlockProcessor.cs Overrides block execution context creation to inject an XDC-specific PREVRANDAO.
src/Nethermind/Nethermind.Evm/BlockExecutionContext.cs Refactors BlockExecutionContext construction and adds a WithPrevRandao factory for custom RNG injection.
src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs Introduces a virtual hook for creating BlockExecutionContext and uses it when setting up transaction execution.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


protected override BlockExecutionContext CreateBlockExecutionContext(BlockHeader header, IReleaseSpec spec) =>
BlockExecutionContext.WithPrevRandao(header, spec,
ValueKeccak.Compute(header.Number.ToBigEndianSpanWithoutLeadingZeros(out _)));
Copy link
Contributor

Choose a reason for hiding this comment

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

So for block value of 0 (which we probably won't hit?) I think it will be different from XDC version, as big.Int.Bytes() returns [] in Go, while our version returns [0].

But in general, +1 for a test comparing this function output against static pre-computed XDC values for a few inputs, as I'm not so confident our ToBigEndianSpanWithoutLeadingZeros always matches big.Int.Bytes().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants