@@ -10,6 +10,7 @@ import (
1010 "github.com/stretchr/testify/assert"
1111 "github.com/stretchr/testify/require"
1212
13+ "github.com/ethereum/go-ethereum/common"
1314 "github.com/ethereum/go-ethereum/core/vm"
1415 "github.com/ethereum/go-ethereum/libevm/ethtest"
1516 "github.com/ethereum/go-ethereum/libevm/hookstest"
@@ -35,6 +36,16 @@ func (s *vmHooksStub) OverrideJumpTable(_ params.Rules, jt *vm.JumpTable) *vm.Ju
3536 return jt
3637}
3738
39+ // An opRecorder is an instruction that records its inputs.
40+ type opRecorder struct {
41+ stateVal common.Hash
42+ }
43+
44+ func (op * opRecorder ) execute (env * vm.OperationEnvironment , pc * uint64 , interpreter * vm.EVMInterpreter , scope * vm.ScopeContext ) ([]byte , error ) {
45+ op .stateVal = env .StateDB .GetState (scope .Contract .Address (), common.Hash {})
46+ return nil , nil
47+ }
48+
3849func TestOverrideJumpTable (t * testing.T ) {
3950 override := new (bool )
4051 hooks := & hookstest.Stub {
@@ -50,15 +61,12 @@ func TestOverrideJumpTable(t *testing.T) {
5061 )
5162 rng := ethtest .NewPseudoRand (142857 )
5263 gasCost := 1 + rng .Uint64n (gasLimit )
53- executed := false
64+ spy := & opRecorder {}
5465
5566 vmHooks := & vmHooksStub {
5667 replacement : & vm.JumpTable {
5768 opcode : vm.OperationBuilder {
58- Execute : func (pc * uint64 , interpreter * vm.EVMInterpreter , callContext * vm.ScopeContext ) ([]byte , error ) {
59- executed = true
60- return nil , nil
61- },
69+ Execute : spy .execute ,
6270 ConstantGas : gasCost ,
6371 MemorySize : func (s * vm.Stack ) (size uint64 , overflow bool ) {
6472 return 0 , false
@@ -91,11 +99,13 @@ func TestOverrideJumpTable(t *testing.T) {
9199 contract := rng .Address ()
92100 state .CreateAccount (contract )
93101 state .SetCode (contract , []byte {opcode })
102+ value := rng .Hash ()
103+ state .SetState (contract , common.Hash {}, value )
94104
95105 _ , gasRemaining , err := evm .Call (vm .AccountRef (rng .Address ()), contract , []byte {}, gasLimit , uint256 .NewInt (0 ))
96106 require .NoError (t , err , "evm.Call([contract with overridden opcode])" )
97- assert .True (t , executed , "executionFunc was called" )
98107 assert .Equal (t , gasLimit - gasCost , gasRemaining , "gas remaining" )
108+ assert .Equal (t , spy .stateVal , value , "StateDB propagated" )
99109 })
100110}
101111
0 commit comments