From 527ea11e501c5eadfd3e465f490333f8c2de999c Mon Sep 17 00:00:00 2001 From: phrwlk Date: Mon, 13 Apr 2026 16:46:13 +0300 Subject: [PATCH] core/vm/runtime: don't overwrite user input with default value (#33510) runtime.setDefaults was unconditionally assigning cfg.Random = &common.Hash{}, which silently overwrote any caller-provided Random value. This made it impossible to simulate a specific PREVRANDAO and also forced post-merge rules whenever London was active, regardless of the intended environment. This change only initializes cfg.Random when it is nil, matching how other fields in Config are defaulted. Existing callers that did not set Random keep the same behavior (a non-nil zero hash still enables post-merge semantics), while callers that explicitly set Random now get their value respected. --- core/vm/runtime/runtime.go | 4 +++- core/vm/runtime/runtime_test.go | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go index b40e99d047..af394aa054 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -109,7 +109,9 @@ func setDefaults(cfg *Config) { if cfg.BlobBaseFee == nil { cfg.BlobBaseFee = big.NewInt(params.BlobTxMinBlobGasprice) } - cfg.Random = &(common.Hash{}) + if cfg.Random == nil { + cfg.Random = new(common.Hash) + } } // Execute executes the code using the input as call data during the execution. diff --git a/core/vm/runtime/runtime_test.go b/core/vm/runtime/runtime_test.go index a001d81623..40fb770454 100644 --- a/core/vm/runtime/runtime_test.go +++ b/core/vm/runtime/runtime_test.go @@ -65,6 +65,21 @@ func TestDefaults(t *testing.T) { if cfg.BlockNumber == nil { t.Error("expected block number to be non nil") } + if cfg.Random == nil { + t.Error("expected Random to be non nil") + } +} + +func TestDefaultsPreserveRandom(t *testing.T) { + h := common.HexToHash("0x01") + cfg := &Config{Random: &h} + setDefaults(cfg) + if cfg.Random == nil { + t.Fatal("expected Random to remain non-nil") + } + if *cfg.Random != h { + t.Fatalf("expected Random to be preserved, got %x, want %x", *cfg.Random, h) + } } func TestEVM(t *testing.T) {