diff --git a/core/vm/instructions.go b/core/vm/instructions.go index fffa65fd6a..f6359cc3d2 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -990,12 +990,9 @@ func makePush(size uint64, pushByteSize int) executionFunc { start = min(codeLen, int(*pc+1)) end = min(codeLen, start+pushByteSize) ) - a := new(uint256.Int).SetBytes(scope.Contract.Code[start:end]) - - // Missing bytes: pushByteSize - len(pushData) - if missing := pushByteSize - (end - start); missing > 0 { - a.Lsh(a, uint(8*missing)) - } + var b [32]byte + copy(b[:], scope.Contract.Code[start:end]) + a := new(uint256.Int).SetBytes(b[:pushByteSize]) scope.Stack.push(a) *pc += size return nil, nil diff --git a/core/vm/instructions_test.go b/core/vm/instructions_test.go index cd31829a7e..d51a5224da 100644 --- a/core/vm/instructions_test.go +++ b/core/vm/instructions_test.go @@ -973,6 +973,25 @@ func TestPush(t *testing.T) { } } +func BenchmarkPush(b *testing.B) { + code := common.FromHex("ff") + + push32 := makePush(32, 32) + + scope := &ScopeContext{ + Memory: nil, + Stack: newstack(), + Contract: &Contract{ + Code: code, + }, + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + pc := new(uint64) + _, _ = push32(pc, nil, scope) + } +} + func TestOpCLZ(t *testing.T) { evm := NewEVM(BlockContext{}, nil, params.TestChainConfig, Config{})