diff --git a/core/vm/instructions.go b/core/vm/instructions.go index bfc2cef511..fe63bf007c 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -979,9 +979,9 @@ func opPush2(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by integer = new(uint256.Int) ) if *pc+2 < codeLen { - scope.Stack.push(integer.SetUint64(uint64(binary.BigEndian.Uint16(scope.Contract.Code[*pc : *pc+2])))) + scope.Stack.push(integer.SetUint64(uint64(binary.BigEndian.Uint16(scope.Contract.Code[*pc+1 : *pc+3])))) } else if *pc+1 < codeLen { - scope.Stack.push(integer.SetUint64(uint64(scope.Contract.Code[*pc]) << 8)) + scope.Stack.push(integer.SetUint64(uint64(scope.Contract.Code[*pc+1]) << 8)) } else { scope.Stack.push(integer.Clear()) } diff --git a/core/vm/instructions_test.go b/core/vm/instructions_test.go index 43c5e9cda3..9829e4a633 100644 --- a/core/vm/instructions_test.go +++ b/core/vm/instructions_test.go @@ -973,11 +973,33 @@ func TestPush(t *testing.T) { } } +func FuzzPush(f *testing.F) { + push2 := makePush(2, 2) + f.Fuzz(func(t *testing.T, code []byte, origPC uint64) { + scope := &ScopeContext{ + Memory: nil, + Stack: newstack(), + Contract: &Contract{ + Code: code, + }, + } + pc := origPC + push2(&pc, nil, scope) + a := scope.Stack.pop() + pc = origPC + opPush2(&pc, nil, scope) + b := scope.Stack.pop() + if a.Cmp(&b) != 0 { + panic(fmt.Sprintf("code: %v origPC: %v, %v %v", code, origPC, a, b)) + } + }) +} + func BenchmarkPush(b *testing.B) { var ( - code = common.FromHex("0011223344556677889900aabbccddeeff0102030405060708090a0b0c0d0e0ff1e1d1c1b1a19181716151413121") - push32 = makePush(2, 2) - scope = &ScopeContext{ + code = common.FromHex("0011223344556677889900aabbccddeeff0102030405060708090a0b0c0d0e0ff1e1d1c1b1a19181716151413121") + push2 = makePush(2, 2) + scope = &ScopeContext{ Memory: nil, Stack: newstack(), Contract: &Contract{ @@ -989,7 +1011,7 @@ func BenchmarkPush(b *testing.B) { b.Run("makePush", func(b *testing.B) { for i := 0; i < b.N; i++ { - push32(pc, nil, scope) + push2(pc, nil, scope) scope.Stack.pop() } }) diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index 6610fa7f9a..ee811b447e 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -631,7 +631,7 @@ func newFrontierInstructionSet() JumpTable { maxStack: maxStack(0, 1), }, PUSH2: { - execute: makePush(2, 2), + execute: opPush2, constantGas: GasFastestStep, minStack: minStack(0, 1), maxStack: maxStack(0, 1),