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

tracer: Account for the L1 Fee in the prestate tracer #279

Closed
wants to merge 1 commit into from
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
5 changes: 4 additions & 1 deletion cmd/evm/internal/t8ntool/tracewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/tracers"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -56,7 +57,9 @@ func (t *traceWriter) CaptureTxEnd(restGas uint64) {
}
}

func (t *traceWriter) CaptureTxStart(gasLimit uint64) { t.inner.CaptureTxStart(gasLimit) }
func (t *traceWriter) CaptureTxStart(gasLimit uint64, l1Cost types.RollupCostData) {
t.inner.CaptureTxStart(gasLimit, l1Cost)
}
func (t *traceWriter) CaptureStart(env *vm.EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
t.inner.CaptureStart(env, from, to, create, input, gas, value)
}
Expand Down
2 changes: 1 addition & 1 deletion core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func (st *StateTransition) innerTransitionDb() (*ExecutionResult, error) {
}

if tracer := st.evm.Config.Tracer; tracer != nil {
tracer.CaptureTxStart(st.initialGas)
tracer.CaptureTxStart(st.initialGas, st.msg.RollupCostData)
defer func() {
if st.msg.IsDepositTx {
tracer.CaptureTxEnd(0)
Expand Down
3 changes: 2 additions & 1 deletion core/vm/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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
Expand All @@ -29,7 +30,7 @@ import (
// if you need to retain them beyond the current call.
type EVMLogger interface {
// Transaction level
CaptureTxStart(gasLimit uint64)
CaptureTxStart(gasLimit uint64, l1Cost types.RollupCostData)
CaptureTxEnd(restGas uint64)
// Top call frame
CaptureStart(env *EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int)
Expand Down
3 changes: 2 additions & 1 deletion eth/tracers/js/goja.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/tracers"
Expand Down Expand Up @@ -222,7 +223,7 @@ func newJsTracer(code string, ctx *tracers.Context, cfg json.RawMessage) (tracer

// CaptureTxStart implements the Tracer interface and is invoked at the beginning of
// transaction processing.
func (t *jsTracer) CaptureTxStart(gasLimit uint64) {
func (t *jsTracer) CaptureTxStart(gasLimit uint64, l1Cost types.RollupCostData) {
t.gasLimit = gasLimit
}

Expand Down
3 changes: 2 additions & 1 deletion eth/tracers/js/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/tracers"
"github.com/ethereum/go-ethereum/params"
Expand Down Expand Up @@ -73,7 +74,7 @@ func runTrace(tracer tracers.Tracer, vmctx *vmContext, chaincfg *params.ChainCon
contract.Code = contractCode
}

tracer.CaptureTxStart(gasLimit)
tracer.CaptureTxStart(gasLimit, types.RollupCostData{})
tracer.CaptureStart(env, contract.Caller(), contract.Address(), false, []byte{}, startGas, value)
ret, err := env.Interpreter().Run(contract, []byte{}, false)
tracer.CaptureEnd(ret, startGas-contract.Gas, err)
Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/logger/access_list_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (*AccessListTracer) CaptureEnter(typ vm.OpCode, from common.Address, to com

func (*AccessListTracer) CaptureExit(output []byte, gasUsed uint64, err error) {}

func (*AccessListTracer) CaptureTxStart(gasLimit uint64) {}
func (*AccessListTracer) CaptureTxStart(gasLimit uint64, l1Cost types.RollupCostData) {}

func (*AccessListTracer) CaptureTxEnd(restGas uint64) {}

Expand Down
4 changes: 2 additions & 2 deletions eth/tracers/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (l *StructLogger) Stop(err error) {
l.interrupt.Store(true)
}

func (l *StructLogger) CaptureTxStart(gasLimit uint64) {
func (l *StructLogger) CaptureTxStart(gasLimit uint64, l1Cost types.RollupCostData) {
l.gasLimit = gasLimit
}

Expand Down Expand Up @@ -395,7 +395,7 @@ func (t *mdLogger) CaptureEnter(typ vm.OpCode, from common.Address, to common.Ad

func (t *mdLogger) CaptureExit(output []byte, gasUsed uint64, err error) {}

func (*mdLogger) CaptureTxStart(gasLimit uint64) {}
func (*mdLogger) CaptureTxStart(gasLimit uint64, l1Cost types.RollupCostData) {}

func (*mdLogger) CaptureTxEnd(restGas uint64) {}

Expand Down
3 changes: 2 additions & 1 deletion eth/tracers/logger/logger_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
)

Expand Down Expand Up @@ -97,6 +98,6 @@ func (l *JSONLogger) CaptureEnter(typ vm.OpCode, from common.Address, to common.

func (l *JSONLogger) CaptureExit(output []byte, gasUsed uint64, err error) {}

func (l *JSONLogger) CaptureTxStart(gasLimit uint64) {}
func (l *JSONLogger) CaptureTxStart(gasLimit uint64, l1Cost types.RollupCostData) {}

func (l *JSONLogger) CaptureTxEnd(restGas uint64) {}
3 changes: 2 additions & 1 deletion eth/tracers/native/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/tracers"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -243,7 +244,7 @@ func (t *callTracer) CaptureExit(output []byte, gasUsed uint64, err error) {
t.callstack[size-1].Calls = append(t.callstack[size-1].Calls, call)
}

func (t *callTracer) CaptureTxStart(gasLimit uint64) {
func (t *callTracer) CaptureTxStart(gasLimit uint64, l1Cost types.RollupCostData) {
t.gasLimit = gasLimit
}

Expand Down
5 changes: 3 additions & 2 deletions eth/tracers/native/call_flat.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/tracers"
)
Expand Down Expand Up @@ -201,8 +202,8 @@ func (t *flatCallTracer) CaptureExit(output []byte, gasUsed uint64, err error) {
}
}

func (t *flatCallTracer) CaptureTxStart(gasLimit uint64) {
t.tracer.CaptureTxStart(gasLimit)
func (t *flatCallTracer) CaptureTxStart(gasLimit uint64, l1Cost types.RollupCostData) {
t.tracer.CaptureTxStart(gasLimit, l1Cost)
}

func (t *flatCallTracer) CaptureTxEnd(restGas uint64) {
Expand Down
5 changes: 3 additions & 2 deletions eth/tracers/native/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/tracers"
)
Expand Down Expand Up @@ -101,9 +102,9 @@ func (t *muxTracer) CaptureExit(output []byte, gasUsed uint64, err error) {
}
}

func (t *muxTracer) CaptureTxStart(gasLimit uint64) {
func (t *muxTracer) CaptureTxStart(gasLimit uint64, l1Cost types.RollupCostData) {
for _, t := range t.tracers {
t.CaptureTxStart(gasLimit)
t.CaptureTxStart(gasLimit, l1Cost)
}
}

Expand Down
3 changes: 2 additions & 1 deletion eth/tracers/native/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/tracers"
)
Expand Down Expand Up @@ -63,7 +64,7 @@ func (t *noopTracer) CaptureEnter(typ vm.OpCode, from common.Address, to common.
func (t *noopTracer) CaptureExit(output []byte, gasUsed uint64, err error) {
}

func (*noopTracer) CaptureTxStart(gasLimit uint64) {}
func (*noopTracer) CaptureTxStart(gasLimit uint64, l1Cost types.RollupCostData) {}

func (*noopTracer) CaptureTxEnd(restGas uint64) {}

Expand Down
13 changes: 11 additions & 2 deletions eth/tracers/native/prestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/tracers"
Expand Down Expand Up @@ -61,7 +62,8 @@ type prestateTracer struct {
post state
create bool
to common.Address
gasLimit uint64 // Amount of gas bought for the whole tx
gasLimit uint64 // Amount of gas bought for the whole tx
l1Cost types.RollupCostData // Info on to see how much a non-deposit cost
config prestateTracerConfig
interrupt atomic.Bool // Atomic flag to signal execution interruption
reason error // Textual reason for the interruption
Expand Down Expand Up @@ -109,6 +111,12 @@ func (t *prestateTracer) CaptureStart(env *vm.EVM, from common.Address, to commo
gasPrice := env.TxContext.GasPrice
consumedGas := new(big.Int).Mul(gasPrice, new(big.Int).SetUint64(t.gasLimit))
fromBal.Add(fromBal, new(big.Int).Add(value, consumedGas))
// Undo the L1 Fee if optimism
if env.Context.L1CostFunc != nil {
l1Cost := env.Context.L1CostFunc(t.l1Cost, env.Context.Time)
fromBal.Add(fromBal, l1Cost)
}

t.pre[from].Balance = fromBal
t.pre[from].Nonce--

Expand Down Expand Up @@ -179,8 +187,9 @@ func (t *prestateTracer) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64,
}
}

func (t *prestateTracer) CaptureTxStart(gasLimit uint64) {
func (t *prestateTracer) CaptureTxStart(gasLimit uint64, l1Cost types.RollupCostData) {
t.gasLimit = gasLimit
t.l1Cost = l1Cost
}

func (t *prestateTracer) CaptureTxEnd(restGas uint64) {
Expand Down
Loading