diff --git a/core/vm/instructions.go b/core/vm/instructions.go index fffa65fd6a..0870ff8818 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -920,6 +920,26 @@ func opSelfdestruct6780(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, erro return nil, errStopToken } +func opLog0(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) { + if evm.readOnly { + return nil, ErrWriteProtection + } + stack := scope.Stack + mStart, mSize := stack.pop(), stack.pop() + + d := scope.Memory.GetCopy(mStart.Uint64(), mSize.Uint64()) + evm.StateDB.AddLog(&types.Log{ + Address: scope.Contract.Address(), + Topics: nil, + Data: d, + // This is a non-consensus field, but assigned here because + // core/state doesn't know the current block number. + BlockNumber: evm.Context.BlockNumber.Uint64(), + }) + + return nil, nil +} + // following functions are used by the instruction jump table // make log instruction function diff --git a/core/vm/instructions_test.go b/core/vm/instructions_test.go index cd31829a7e..f24d90e4fb 100644 --- a/core/vm/instructions_test.go +++ b/core/vm/instructions_test.go @@ -559,6 +559,29 @@ func BenchmarkOpMstore(bench *testing.B) { } } +func BenchmarkOpLog0(bench *testing.B) { + var ( + statedb, _ = state.New(types.EmptyRootHash, state.NewDatabaseForTesting()) + evm = NewEVM(BlockContext{BlockNumber: big1}, statedb, params.TestChainConfig, Config{}) + stack = newstack() + mem = NewMemory() + caller = common.Address{} + to = common.Address{1} + contract = NewContract(caller, to, new(uint256.Int), 0, nil) + ) + mem.Resize(64) + pc := uint64(0) + memStart := new(uint256.Int) + size := new(uint256.Int).SetUint64(64) + + bench.ResetTimer() + for i := 0; i < bench.N; i++ { + stack.push(size) + stack.push(memStart) + _, _ = opLog0(&pc, evm, &ScopeContext{mem, stack, contract}) + } +} + func TestOpTstore(t *testing.T) { var ( statedb, _ = state.New(types.EmptyRootHash, state.NewDatabaseForTesting()) diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index d7a4d9da1d..1282e7a4a9 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -1005,7 +1005,7 @@ func newFrontierInstructionSet() JumpTable { maxStack: maxSwapStack(17), }, LOG0: { - execute: makeLog(0), + execute: opLog0, dynamicGas: makeGasLog(0), minStack: minStack(2, 0), maxStack: maxStack(2, 0),