Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update EVM trace log capturing #356

Closed
wants to merge 22 commits into from
Closed

Update EVM trace log capturing #356

wants to merge 22 commits into from

Conversation

trinhdn2
Copy link

@trinhdn2 trinhdn2 commented Jun 14, 2023

This PR unifies the way we collect step-by-step logs about opcodes, call frames of a specific EVM execution. It will enable us to trace/debug transactions and smart contract calls, implement native Golang tracers (instead of current slow JS tracers) and serve more tracer APIs in the near future.

type EVMLogger interface {
	CaptureTxStart(gasLimit uint64)
	CaptureTxEnd(restGas uint64)
	CaptureStart(env *EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int)
	CaptureEnd(output []byte, gasUsed uint64, err error)
	CaptureEnter(typ OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int)
	CaptureExit(output []byte, gasUsed uint64, err error)
	CaptureState(pc uint64, op OpCode, gas, cost uint64, scope *CallCtx, rData []byte, depth int, err error)
	CaptureFault(pc uint64, op OpCode, gas, cost uint64, scope *CallCtx, depth int, err error)
}

An example of debug_traceTransaction API result:

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "gas": 100327,
        "failed": false,
        "returnValue": "6080604052348015600f57600080fd5b506004361060325760003560e01c80632e64cec11460375780636057361d14604c575b600080fd5b60005460405190815260200160405180910390f35b605c6057366004605e565b600055565b005b600060208284031215606f57600080fd5b503591905056fea264697066735822122010f96e94965e51ec23c30c0ae3f9c5b18b9916d523ce1cce4f9f87d707a9e90564736f6c63430008120033",
        "structLogs": [
            {
                "pc": 0,
                "op": "PUSH1",
                "gas": 34487,
                "gasCost": 3,
                "depth": 1,
                "stack": []
            },
            ...
            {
                "pc": 28,
                "op": "RETURN",
                "gas": 34400,
                "gasCost": 0,
                "depth": 1,
                "stack": [
                    "00000000000000000000000000000000000000000000000000000000000000ac",
                    "0000000000000000000000000000000000000000000000000000000000000000"
                ]
            }
        ]
    }
}

Checklist

  • Separate StructLog, JSONLogger and JS tracers into sub-packages inside tracers
  • Update above packages to implement the new EVMLogger interface
  • Expose attributes of the vm.CallCtx struct, Config of vm.EVM
  • Put logger methods to EVM execution flow to capture trace logs

References

@trinhdn2 trinhdn2 marked this pull request as ready for review June 15, 2023 09:55
@trinhdn2 trinhdn2 changed the base branch from master to upgrade-core-develop July 3, 2023 05:36
@tungng98 tungng98 deleted the branch BuildOnViction:upgrade-core-develop December 10, 2023 16:51
@tungng98 tungng98 closed this Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants