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

core,eth: implement tx-level hooks for tracers #24510

Merged
merged 18 commits into from
Mar 31, 2022
Merged
Prev Previous commit
Next Next commit
fix intrinsic gas for prestate tracer
  • Loading branch information
s1na committed Mar 30, 2022
commit a59d257fac98efe80e069de4b52a918ca5bd5ec0
18 changes: 7 additions & 11 deletions eth/tracers/native/prestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/tracers"
Expand All @@ -47,6 +46,7 @@ type prestateTracer struct {
prestate prestate
create bool
to common.Address
gasLimit uint64 // Amount of gas bought for the whole tx
interrupt uint32 // Atomic flag to signal execution interruption
reason error // Textual reason for the interruption
}
Expand All @@ -63,14 +63,6 @@ func (t *prestateTracer) CaptureStart(env *vm.EVM, from common.Address, to commo
t.create = create
t.to = to

// Compute intrinsic gas
isHomestead := env.ChainConfig().IsHomestead(env.Context.BlockNumber)
isIstanbul := env.ChainConfig().IsIstanbul(env.Context.BlockNumber)
intrinsicGas, err := core.IntrinsicGas(input, nil, create, isHomestead, isIstanbul)
if err != nil {
return
}

t.lookupAccount(from)
t.lookupAccount(to)

Expand All @@ -82,6 +74,7 @@ func (t *prestateTracer) CaptureStart(env *vm.EVM, from common.Address, to commo
// The sender balance is after reducing: value, gasLimit, intrinsicGas.
// We need to re-add them to get the pre-tx balance.
fromBal := hexutil.MustDecodeBig(t.prestate[from].Balance)
intrinsicGas := t.gasLimit - gas
Copy link
Member

@rjl493456442 rjl493456442 Mar 31, 2022

Choose a reason for hiding this comment

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

The consumedGas is always equivalent to t.gasLimit right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I was doing gasLimit - gas + gas haha

gasPrice := env.TxContext.GasPrice
consumedGas := new(big.Int).Mul(
gasPrice,
Expand Down Expand Up @@ -145,8 +138,11 @@ func (t *prestateTracer) CaptureEnter(typ vm.OpCode, from common.Address, to com
func (t *prestateTracer) CaptureExit(output []byte, gasUsed uint64, err error) {
}

func (*prestateTracer) CaptureTxStart(_ uint64) {}
func (*prestateTracer) CaptureTxEnd(_ uint64, _ error) {}
func (t *prestateTracer) CaptureTxStart(gasLimit uint64) {
t.gasLimit = gasLimit
}

func (t *prestateTracer) CaptureTxEnd(restGas uint64, err error) {}

// GetResult returns the json-encoded nested list of call traces, and any
// error arising from the encoding or forceful termination (via `Stop`).
Expand Down