Skip to content

Commit b9e1713

Browse files
core: correctly pass random config
1 parent d50bc52 commit b9e1713

File tree

7 files changed

+18
-3
lines changed

7 files changed

+18
-3
lines changed

core/blockchain_reader.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@ func (bc *BlockChain) GetVMConfig() *vm.Config {
343343
return &bc.vmConfig
344344
}
345345

346+
// SetVMConfig sets the vm config.
347+
// Warning: might not be threadsafe with other components
348+
func (bc *BlockChain) SetVMConfig(config vm.Config) {
349+
bc.vmConfig = config
350+
}
351+
346352
// SetTxLookupLimit is responsible for updating the txlookup limit to the
347353
// original one stored in db if the new mismatches with the old one.
348354
func (bc *BlockChain) SetTxLookupLimit(limit uint64) {

core/state_transition.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
307307
}
308308

309309
// Set up the initial access list.
310-
if rules := st.evm.ChainConfig().Rules(st.evm.Context.BlockNumber, false); rules.IsBerlin {
310+
if rules := st.evm.ChainConfig().Rules(st.evm.Context.BlockNumber, st.evm.Config.RandomOpcode); rules.IsBerlin {
311311
st.state.PrepareAccessList(msg.From(), msg.To(), vm.ActivePrecompiles(rules), msg.AccessList())
312312
}
313313
var (

core/vm/evm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig
132132
StateDB: statedb,
133133
Config: config,
134134
chainConfig: chainConfig,
135-
chainRules: chainConfig.Rules(blockCtx.BlockNumber, blockCtx.Difficulty == nil),
135+
chainRules: chainConfig.Rules(blockCtx.BlockNumber, config.RandomOpcode),
136136
}
137137
evm.interpreter = NewEVMInterpreter(evm, config)
138138
return evm

core/vm/instructions_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ func TestRandom(t *testing.T) {
665665
{name: "hash(0x010203)", random: crypto.Keccak256Hash([]byte{0x01, 0x02, 0x03})},
666666
} {
667667
var (
668-
env = NewEVM(BlockContext{Random: tt.random}, TxContext{}, nil, params.TestChainConfig, Config{})
668+
env = NewEVM(BlockContext{Random: tt.random}, TxContext{}, nil, params.TestChainConfig, Config{RandomOpcode: true})
669669
stack = newstack()
670670
pc = uint64(0)
671671
evmInterpreter = env.interpreter

core/vm/interpreter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type Config struct {
3131
Tracer EVMLogger // Opcode logger
3232
NoRecursion bool // Disables call, callcode, delegate call and create
3333
NoBaseFee bool // Forces the EIP-1559 baseFee to 0 (needed for 0 price calls)
34+
RandomOpcode bool // Enables the random opcode
3435
EnablePreimageRecording bool // Enables recording of SHA3/keccak preimages
3536

3637
JumpTable [256]*operation // EVM instruction table, automatically populated if unset

eth/catalyst/api.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ type blockExecutionEnv struct {
133133

134134
func (env *blockExecutionEnv) commitTransaction(tx *types.Transaction, coinbase common.Address) error {
135135
vmconfig := *env.chain.GetVMConfig()
136+
vmconfig.RandomOpcode = true
136137
snap := env.state.Snapshot()
137138
receipt, err := core.ApplyTransaction(env.chain.Config(), env.chain, &coinbase, env.gasPool, env.state, env.header, tx, &env.header.GasUsed, vmconfig)
138139
if err != nil {
@@ -272,6 +273,9 @@ func (api *ConsensusAPI) ExecutePayloadV1(params ExecutableDataV1) (ExecutePaylo
272273
if td.Cmp(ttd) < 0 {
273274
return api.invalid(), fmt.Errorf("can not execute payload on top of block with low td got: %v threshold %v", td, ttd)
274275
}
276+
conf := api.eth.BlockChain().GetVMConfig()
277+
conf.RandomOpcode = true
278+
api.eth.BlockChain().SetVMConfig(*conf)
275279
if err := api.eth.BlockChain().InsertBlockWithoutSetHead(block); err != nil {
276280
return api.invalid(), err
277281
}
@@ -316,6 +320,9 @@ func (api *ConsensusAPI) assembleBlock(parentHash common.Hash, params *PayloadAt
316320
Time: params.Timestamp,
317321
MixDigest: params.Random,
318322
}
323+
conf := api.eth.BlockChain().GetVMConfig()
324+
conf.RandomOpcode = true
325+
api.eth.BlockChain().SetVMConfig(*conf)
319326
if config := api.eth.BlockChain().Config(); config.IsLondon(header.Number) {
320327
header.BaseFee = misc.CalcBaseFee(config, parent.Header())
321328
}

tests/state_test_util.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
221221
context.GetHash = vmTestBlockHash
222222
context.BaseFee = baseFee
223223
if t.json.Env.Random != nil {
224+
vmconfig.RandomOpcode = true
224225
context.Random = common.BigToHash(t.json.Env.Random)
225226
context.Difficulty = nil
226227
}

0 commit comments

Comments
 (0)