Skip to content

Commit

Permalink
core/vm/runtime: set random to enable merge-opcodes (ethereum#29799)
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman authored and jorgemmsilva committed Jun 17, 2024
1 parent 2021943 commit 9a6bcb2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
45 changes: 29 additions & 16 deletions core/vm/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,33 @@ type Config struct {
// sets defaults on the config
func setDefaults(cfg *Config) {
if cfg.ChainConfig == nil {
var (
shanghaiTime = uint64(0)
cancunTime = uint64(0)
)
cfg.ChainConfig = &params.ChainConfig{
ChainID: big.NewInt(1),
HomesteadBlock: new(big.Int),
DAOForkBlock: new(big.Int),
DAOForkSupport: false,
EIP150Block: new(big.Int),
EIP155Block: new(big.Int),
EIP158Block: new(big.Int),
ByzantiumBlock: new(big.Int),
ConstantinopleBlock: new(big.Int),
PetersburgBlock: new(big.Int),
IstanbulBlock: new(big.Int),
MuirGlacierBlock: new(big.Int),
BerlinBlock: new(big.Int),
LondonBlock: new(big.Int),
}
ChainID: big.NewInt(1),
HomesteadBlock: new(big.Int),
DAOForkBlock: new(big.Int),
DAOForkSupport: false,
EIP150Block: new(big.Int),
EIP155Block: new(big.Int),
EIP158Block: new(big.Int),
ByzantiumBlock: new(big.Int),
ConstantinopleBlock: new(big.Int),
PetersburgBlock: new(big.Int),
IstanbulBlock: new(big.Int),
MuirGlacierBlock: new(big.Int),
BerlinBlock: new(big.Int),
LondonBlock: new(big.Int),
ArrowGlacierBlock: nil,
GrayGlacierBlock: nil,
TerminalTotalDifficulty: big.NewInt(0),
TerminalTotalDifficultyPassed: true,
MergeNetsplitBlock: nil,
ShanghaiTime: &shanghaiTime,
CancunTime: &cancunTime}
}

if cfg.Difficulty == nil {
cfg.Difficulty = new(big.Int)
}
Expand All @@ -101,6 +110,10 @@ func setDefaults(cfg *Config) {
if cfg.BlobBaseFee == nil {
cfg.BlobBaseFee = big.NewInt(params.BlobTxMinBlobGasprice)
}
// Merge indicators
if t := cfg.ChainConfig.ShanghaiTime; cfg.ChainConfig.TerminalTotalDifficultyPassed || (t != nil && *t == 0) {
cfg.Random = &(common.Hash{})
}
}

// Execute executes the code using the input as call data during the execution.
Expand Down
6 changes: 3 additions & 3 deletions core/vm/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestExecute(t *testing.T) {

func TestCall(t *testing.T) {
state, _ := state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
address := common.HexToAddress("0x0a")
address := common.HexToAddress("0xaa")
state.SetCode(address, []byte{
byte(vm.PUSH1), 10,
byte(vm.PUSH1), 0,
Expand Down Expand Up @@ -725,7 +725,7 @@ func TestRuntimeJSTracer(t *testing.T) {
byte(vm.CREATE),
byte(vm.POP),
},
results: []string{`"1,1,952855,6,12"`, `"1,1,952855,6,0"`},
results: []string{`"1,1,952853,6,12"`, `"1,1,952853,6,0"`},
},
{
// CREATE2
Expand All @@ -741,7 +741,7 @@ func TestRuntimeJSTracer(t *testing.T) {
byte(vm.CREATE2),
byte(vm.POP),
},
results: []string{`"1,1,952846,6,13"`, `"1,1,952846,6,0"`},
results: []string{`"1,1,952844,6,13"`, `"1,1,952844,6,0"`},
},
{
// CALL
Expand Down

0 comments on commit 9a6bcb2

Please sign in to comment.