Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

EVMC tracing for interpreter #5065

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open

EVMC tracing for interpreter #5065

wants to merge 19 commits into from

Conversation

chfast
Copy link
Collaborator

@chfast chfast commented Jun 5, 2018

This is a preview of the EVMC feature ethereum/evmc#32.

Changes

  1. The trace reflects the state of the VM after the execution of an opcode.
  2. This allows to include the error code in the trace.
  3. You can also show the result of the opcode execution (top stack item).
  4. The full VM stack is not reported, only the result of the opcode pushed on the stack (if any). This limits the amount of data transferred, but tracking SWAP and DUP instructions requires some work on the Client side.
  5. Only the fragment of the memory modified by the opcode is reported to the Client. It is easy to incrementally patch the Client's memory view if needed.
  6. The opcode is not reported. The Client knows what code is executed and can get the opcode using the code_offset. It might be convenient to revert this decision and send the opcode to the Client.
  7. The tracing data collection is separated from formatting.
  8. I believe you can construct a formatter which will replicate the behavior of legacy traces.

Examples

testeth -t GeneralStateTests/stCallCodes -- --verbosity 2 --singlenet Byzantium --singletest callcallcallcode_001_SuicideMiddle --vmtrace --vm interpreter
>>>> CALL gas: 2979000
0000  PUSH1 (40)
0002  PUSH1 (0)
0004  PUSH1 (40)
0006  PUSH1 (0)
0008  PUSH1 (0)
000a  PUSH20 (1000000000000000000000000000000000000001)
001f  PUSH3 (249F0)
0023  CALL (40)
>>>>  CALL gas: 150000
0000   PUSH1 (40)
0002   PUSH1 (0)
0004   PUSH1 (40)
0006   PUSH1 (0)
0008   PUSH1 (0)
000a   PUSH20 (1000000000000000000000000000000000000002)
001f   PUSH3 (186A0)
0023   CALL (40)
>>>>   CALL gas: 100000
0000    PUSH20 (1000000000000000000000000000000000000000)
0015    SELFDESTRUCT
<<<<
0024   PUSH1 (1)
0026   SSTORE
<<<<
0024  PUSH1 (0)
0026  SSTORE
<<<<
test/testeth -t 'GeneralStateTests/stCreateTest' -- --verbosity 2 --singlenet Byzantium --singletest CREATE_EmptyContractWithStorageAndCallIt_0wei --vmtrace --vm interpreter
>>>> CALL gas: 579000
0000  GAS (8D5B6)
0001  PUSH1 (0)
0003  SSTORE
0004  PUSH32 (600C6000556000600060006000600073C94F5374FCE5EDBC8E2A8697C1533167)
0025  PUSH1 (0)
0027  MSTORE
0028  PUSH32 (7E6EBF0B61EA60F1000000000000000000000000000000000000000000000000)
0049  PUSH1 (20)
004b  MSTORE
004c  PUSH1 (40)
004e  PUSH1 (0)
0050  PUSH1 (0)
0052  CREATE (40)
>>>>  CREATE gas: 518729
0000   PUSH1 (C)
0002   PUSH1 (0)
0004   SSTORE
0005   PUSH1 (0)
0007   PUSH1 (0)
0009   PUSH1 (0)
000b   PUSH1 (0)
000d   PUSH1 (0)
000f   PUSH20 (C94F5374FCE5EDBC8E2A8697C15331677E6EBF0B)
0024   PUSH2 (EA60)
0027   CALL (0)
>>>>   CALL gas: 60000
0000    PUSH1 (C)
0002    PUSH1 (1)
0004    SSTORE
<<<<
0028   STOP
<<<<
0053  PUSH1 (1)
0055  SSTORE
0056  GAS (71D30)
0057  PUSH1 (2)
0059  SSTORE
005a  PUSH1 (0)
005c  PUSH1 (0)
005e  PUSH1 (0)
0060  PUSH1 (0)
0062  PUSH1 (0)
0064  PUSH1 (1)
0066  SLOAD (F1ECF98489FA9ED60A664FC4998DB699CFA39D40)
0067  PUSH2 (EA60)
006a  CALL (0)
006b  PUSH1 (3)
006d  SSTORE
006e  GAS (67D4F)
006f  PUSH1 (64)
0071  SSTORE
<<<<

As you may see, there are at least 2 nice features here:

  1. Internal calls are properly attached to call instructions.
  2. You can see the outcome of an instruction, e.g. ADD (3) means that the result of the addition was 3.

The call instructions are not handled correctly yet. Now they are reported just before the internal call, but I want them to be reported after because this is more consistent and allows showing the returned values (CALL (1), CALL (0), CREATE (<created address>)).

@chfast
Copy link
Collaborator Author

chfast commented Jun 5, 2018

cc @cdetrio

gumb0
gumb0 previously requested changes Jun 7, 2018
libevm/EVMC.cpp Outdated Show resolved Hide resolved
libevm/EVMC.cpp Outdated Show resolved Hide resolved
libevm/EVMC.cpp Outdated Show resolved Hide resolved
@chfast
Copy link
Collaborator Author

chfast commented Jun 7, 2018

@gumb0 The cpp-ethereum part is a prototype to check if the EVMC API is ok.

@axic
Copy link
Member

axic commented Jul 25, 2018

Needs to be rebased and adapted to the latest version of ethereum/evmc#32.

@chfast
Copy link
Collaborator Author

chfast commented Jul 26, 2018

@gumb0 Do you maybe have some spare time to take it over?

libevm/VM.cpp Outdated Show resolved Hide resolved
libevm/VM.cpp Outdated Show resolved Hide resolved
@gumb0 gumb0 force-pushed the evmc-tracing branch 2 times, most recently from e097de1 to f324cc2 Compare August 1, 2018 16:48
@chfast chfast changed the base branch from develop to master August 2, 2018 08:37
@codecov-io
Copy link

codecov-io commented Aug 2, 2018

Codecov Report

Merging #5065 into master will decrease coverage by 0.08%.
The diff coverage is 73.82%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5065      +/-   ##
==========================================
- Coverage   60.81%   60.73%   -0.09%     
==========================================
  Files         341      341              
  Lines       28127    28307     +180     
  Branches     3247     3260      +13     
==========================================
+ Hits        17106    17192      +86     
- Misses       9891     9975      +84     
- Partials     1130     1140      +10

@gumb0 gumb0 dismissed their stale review August 6, 2018 14:03

addressed my own notes

@gumb0 gumb0 force-pushed the evmc-tracing branch 3 times, most recently from 7dd24d3 to 7042f6a Compare August 7, 2018 13:21
@axic

This comment has been minimized.

@axic

This comment has been minimized.

@axic

This comment has been minimized.

libevm/EVMC.h Show resolved Hide resolved
LOG(evmc->m_vmTraceLogger) << logMessage.str();
};

_instance->set_tracer(_instance, tracer, reinterpret_cast<evmc_tracer_context*>(this));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use evmc_set_tracer here.

@chfast
Copy link
Collaborator Author

chfast commented Nov 20, 2018

Updated, please check the description.
cc @holiman @karalabe.

@gumb0
Copy link
Member

gumb0 commented Jun 17, 2019

Here's the summary of what is affected in aleth by changes in tracing:

  • VM trace output in logs at TRACE verbosity for aleth and testeth
  • --jsontrace option of testeth
  • Trace output and opcode stats counting in aleth-vm tool
  • admin_eth_vmTrace and debug_trace* RPC methods
  • some VM unit tests use trace callback to check the opcode price

@chfast
Copy link
Collaborator Author

chfast commented Jun 17, 2019

The tracing API in EVMC has some flaws and will have to redesigned. But the amount of data transferred from the VM is good.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants