Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ func makeLog(size int) executionFunc {
mStart, mSize := stack.pop(), stack.pop()
for i := 0; i < size; i++ {
addr := stack.pop()
topics[i] = addr.Bytes32()
addr.WriteToArray32((*[32]byte)(&topics[i]))
}

d := scope.Memory.GetCopy(mStart.Uint64(), mSize.Uint64())
Expand Down
35 changes: 35 additions & 0 deletions core/vm/instructions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1008,3 +1008,38 @@ func TestOpCLZ(t *testing.T) {
}
}
}

func BenchmarkLog3(b *testing.B) {
var (
statedb, _ = state.New(types.EmptyRootHash, state.NewDatabaseForTesting())
evm = NewEVM(BlockContext{BlockNumber: big.NewInt(1), Time: 1, Random: &common.Hash{}}, statedb, params.MergedTestChainConfig, Config{})
startGas uint64 = 100_000_000
value = uint256.NewInt(0)
contract = NewContract(common.Address{}, common.Address{}, value, startGas, nil)
scope = &ScopeContext{
Contract: contract,
Memory: NewMemory(),
Stack: new(Stack),
}
)
// get log3 executor
exec := makeLog(3)
for b.Loop() {
// memory data
data := []byte("hello world, this is log data")
scope.Memory.Resize(1024)
scope.Memory.Set(0, uint64(len(data)), data)

// LOG3
// stack: mStart, mSize, topic1, topic2, topic3
scope.Stack.push(uint256.NewInt(1))
scope.Stack.push(uint256.NewInt(2))
scope.Stack.push(uint256.NewInt(3))
scope.Stack.push(uint256.NewInt(uint64(len(data)))) // mSize
scope.Stack.push(uint256.NewInt(0)) // mStart
_, err := exec(nil, evm, scope)
if err != nil {
b.Fatal(err)
}
}
}