From 8751ba7513f2200efc84735668d0eacbf0ec3ca0 Mon Sep 17 00:00:00 2001 From: easyfold <137396765+easyfold@users.noreply.github.com> Date: Fri, 20 Sep 2024 15:44:37 +0800 Subject: [PATCH] tracer: fix incorrect gasUsed in deposit tx --- core/state_transition.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/core/state_transition.go b/core/state_transition.go index a23a26468e..d5e560710d 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -442,7 +442,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { return result, err } -func (st *StateTransition) innerTransitionDb() (*ExecutionResult, error) { +func (st *StateTransition) innerTransitionDb() (_ *ExecutionResult, err error) { // First check this message satisfies all consensus rules before // applying the message. The rules include these clauses // @@ -458,10 +458,20 @@ func (st *StateTransition) innerTransitionDb() (*ExecutionResult, error) { return nil, err } + var ( + msg = st.msg + sender = vm.AccountRef(msg.From) + rules = st.evm.ChainConfig().Rules(st.evm.Context.BlockNumber, st.evm.Context.Random != nil, st.evm.Context.Time) + contractCreation = msg.To == nil + ) + if tracer := st.evm.Config.Tracer; tracer != nil { tracer.CaptureTxStart(st.initialGas) defer func() { - if st.msg.IsDepositTx { + if st.msg.IsDepositTx && !rules.IsOptimismRegolith && err == nil { + if st.msg.IsSystemTx { + tracer.CaptureTxEnd(st.msg.GasLimit) + } tracer.CaptureTxEnd(0) } else { tracer.CaptureTxEnd(st.gasRemaining) @@ -469,13 +479,6 @@ func (st *StateTransition) innerTransitionDb() (*ExecutionResult, error) { }() } - var ( - msg = st.msg - sender = vm.AccountRef(msg.From) - rules = st.evm.ChainConfig().Rules(st.evm.Context.BlockNumber, st.evm.Context.Random != nil, st.evm.Context.Time) - contractCreation = msg.To == nil - ) - // Check clauses 4-5, subtract intrinsic gas if everything is correct gas, err := IntrinsicGas(msg.Data, msg.AccessList, contractCreation, rules.IsHomestead, rules.IsIstanbul, rules.IsShanghai) if err != nil {