118 lines
6.4 KiB
Go
118 lines
6.4 KiB
Go
// Copyright 2015 The go-ethereum Authors
|
|
// This file is part of the go-ethereum library.
|
|
//
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package vm
|
|
|
|
import (
|
|
"math/big"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
)
|
|
|
|
// EVMLogger is used to collect execution traces from an EVM transaction
|
|
// execution. CaptureState is called for each step of the VM with the
|
|
// current VM state.
|
|
// Note that reference types are actual VM data structures; make copies
|
|
// if you need to retain them beyond the current call.
|
|
type EVMLogger interface {
|
|
// Transaction level
|
|
// Call simulations don't come with a valid signature. `from` field
|
|
// to be used for address of the caller.
|
|
CaptureTxStart(evm *EVM, tx *types.Transaction, from common.Address)
|
|
CaptureTxEnd(receipt *types.Receipt, err error)
|
|
// Top call frame
|
|
CaptureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int)
|
|
// CaptureEnd is invoked when the processing of the top call ends.
|
|
// See docs for `CaptureExit` for info on the `reverted` parameter.
|
|
CaptureEnd(output []byte, gasUsed uint64, err error, reverted bool)
|
|
// Rest of call frames
|
|
CaptureEnter(typ OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int)
|
|
// CaptureExit is invoked when the processing of a message ends.
|
|
// `revert` is true when there was an error during the execution.
|
|
// Exceptionally, before the homestead hardfork a contract creation that
|
|
// ran out of gas when attempting to persist the code to database did not
|
|
// count as a call failure and did not cause a revert of the call. This will
|
|
// be indicated by `reverted == false` and `err == ErrCodeStoreOutOfGas`.
|
|
CaptureExit(output []byte, gasUsed uint64, err error, reverted bool)
|
|
// Opcode level
|
|
CaptureState(pc uint64, op OpCode, gas, cost uint64, scope *ScopeContext, rData []byte, depth int, err error)
|
|
CaptureFault(pc uint64, op OpCode, gas, cost uint64, scope *ScopeContext, depth int, err error)
|
|
CaptureKeccakPreimage(hash common.Hash, data []byte)
|
|
// Misc
|
|
OnGasChange(old, new uint64, reason GasChangeReason)
|
|
}
|
|
|
|
// GasChangeReason is used to indicate the reason for a gas change, useful
|
|
// for tracing and reporting.
|
|
//
|
|
// There is essentially two types of gas changes, those that can be emitted once per transaction
|
|
// and those that can be emitted on a call basis, so possibly multiple times per transaction.
|
|
//
|
|
// They can be recognized easily by their name, those that start with `GasChangeTx` are emitted
|
|
// once per transaction, while those that start with `GasChangeCall` are emitted on a call basis.
|
|
type GasChangeReason byte
|
|
|
|
const (
|
|
GasChangeUnspecified GasChangeReason = iota
|
|
|
|
// GasChangeTxInitialBalance is the initial balance for the call which will be equal to the gasLimit of the call. There is only
|
|
// one such gas change per transaction.
|
|
GasChangeTxInitialBalance
|
|
// GasChangeTxIntrinsicGas is the amount of gas that will be charged for the intrinsic cost of the transaction, there is
|
|
// always exactly one of those per transaction.
|
|
GasChangeTxIntrinsicGas
|
|
// GasChangeTxRefunds is the sum of all refunds which happened during the tx execution (e.g. storage slot being cleared)
|
|
// this generates an increase in gas. There is at most one of such gas change per transaction.
|
|
GasChangeTxRefunds
|
|
// GasChangeTxLeftOverReturned is the amount of gas left over at the end of transaction's execution that will be returned
|
|
// to the chain. This change will always be a negative change as we "drain" left over gas towards 0. If there was no gas
|
|
// left at the end of execution, no such even will be emitted. The returned gas's value in Wei is returned to caller.
|
|
// There is at most one of such gas change per transaction.
|
|
GasChangeTxLeftOverReturned
|
|
|
|
// GasChangeCallInitialBalance is the initial balance for the call which will be equal to the gasLimit of the call. There is only
|
|
// one such gas change per call.
|
|
GasChangeCallInitialBalance
|
|
// GasChangeCallLeftOverReturned is the amount of gas left over that will be returned to the caller, this change will always
|
|
// be a negative change as we "drain" left over gas towards 0. If there was no gas left at the end of execution, no such even
|
|
// will be emitted.
|
|
GasChangeCallLeftOverReturned
|
|
// GasChangeCallLeftOverRefunded is the amount of gas that will be refunded to the call after the child call execution it
|
|
// executed completed. This value is always positive as we are giving gas back to the you, the left over gas of the child.
|
|
// If there was no gas left to be refunded, no such even will be emitted.
|
|
GasChangeCallLeftOverRefunded
|
|
// GasChangeCallContractCreation is the amount of gas that will be burned for a CREATE.
|
|
GasChangeCallContractCreation
|
|
// GasChangeContractCreation is the amount of gas that will be burned for a CREATE2.
|
|
GasChangeCallContractCreation2
|
|
// GasChangeCallCodeStorage is the amount of gas that will be charged for code storage.
|
|
GasChangeCallCodeStorage
|
|
// GasChangeCallOpCode is the amount of gas that will be charged for an opcode executed by the EVM, exact opcode that was
|
|
// performed can be check by `CaptureState` handling.
|
|
GasChangeCallOpCode
|
|
// GasChangeCallPrecompiledContract is the amount of gas that will be charged for a precompiled contract execution.
|
|
GasChangeCallPrecompiledContract
|
|
// GasChangeCallStorageColdAccess is the amount of gas that will be charged for a cold storage access as controlled by EIP2929 rules.
|
|
GasChangeCallStorageColdAccess
|
|
// GasChangeCallFailedExecution is the burning of the remaining gas when the execution failed without a revert.
|
|
GasChangeCallFailedExecution
|
|
|
|
// GasChangeIgnored is a special value that can be used to indicate that the gas change should be ignored as
|
|
// it will be "manually" tracked by a direct emit of the gas change event.
|
|
GasChangeIgnored GasChangeReason = 0xFF
|
|
)
|