mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
WIP: Execute 'ApplyRip7560ValidationPhases' with 'rip7560Validation' tracer
This commit is contained in:
parent
94156da356
commit
99b5f3c08f
3 changed files with 29 additions and 14 deletions
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
|
@ -49,14 +50,14 @@ func (api *Rip7560API) TraceRip7560Validation(
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
msg = args.ToMessage(vmctx.BaseFee)
|
//msg = args.ToMessage(vmctx.BaseFee)
|
||||||
tx = args.ToTransaction()
|
tx = args.ToTransaction()
|
||||||
traceConfig *TraceConfig
|
traceConfig *TraceConfig
|
||||||
)
|
)
|
||||||
if config != nil {
|
if config != nil {
|
||||||
traceConfig = &config.TraceConfig
|
traceConfig = &config.TraceConfig
|
||||||
}
|
}
|
||||||
traceResult, err := api.traceTx(ctx, tx, msg, new(Context), vmctx, statedb, traceConfig)
|
traceResult, err := api.traceTx(ctx, tx, new(Context), block, vmctx, statedb, traceConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -86,12 +87,12 @@ func (api *Rip7560API) chainContext(ctx context.Context) core.ChainContext {
|
||||||
return ethapi.NewChainContext(ctx, api.backend)
|
return ethapi.NewChainContext(ctx, api.backend)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *Rip7560API) traceTx(ctx context.Context, tx *types.Transaction, message *core.Message, txctx *Context, vmctx vm.BlockContext, statedb *state.StateDB, config *TraceConfig) (interface{}, error) {
|
func (api *Rip7560API) traceTx(ctx context.Context, tx *types.Transaction, txctx *Context, block *types.Block, vmctx vm.BlockContext, statedb *state.StateDB, config *TraceConfig) (interface{}, error) {
|
||||||
var (
|
var (
|
||||||
tracer *Tracer
|
tracer *Tracer
|
||||||
err error
|
err error
|
||||||
timeout = defaultTraceTimeout
|
timeout = defaultTraceTimeout
|
||||||
usedGas uint64
|
//usedGas uint64
|
||||||
)
|
)
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = &TraceConfig{}
|
config = &TraceConfig{}
|
||||||
|
|
@ -132,8 +133,15 @@ func (api *Rip7560API) traceTx(ctx context.Context, tx *types.Transaction, messa
|
||||||
|
|
||||||
// Call Prepare to clear out the statedb access list
|
// Call Prepare to clear out the statedb access list
|
||||||
statedb.SetTxContext(txctx.TxHash, txctx.TxIndex)
|
statedb.SetTxContext(txctx.TxHash, txctx.TxIndex)
|
||||||
message.IsRip7560Frame = true
|
gp := new(core.GasPool).AddGas(10000000)
|
||||||
_, err = core.ApplyTransactionWithEVM(message, api.backend.ChainConfig(), new(core.GasPool).AddGas(message.GasLimit), statedb, vmctx.BlockNumber, txctx.BlockHash, tx, &usedGas, vmenv)
|
|
||||||
|
// TODO: this is added to allow our bundler checking the 'TraceValidation' API is supported on Geth
|
||||||
|
if tx.Rip7560TransactionData().Sender.Cmp(common.HexToAddress("0x0000000000000000000000000000000000000000")) == 0 {
|
||||||
|
return tracer.GetResult()
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = core.ApplyRip7560ValidationPhases(api.backend.ChainConfig(), api.chainContext(ctx), nil, gp, statedb, block.Header(), tx, vmenv.Config)
|
||||||
|
//_, err = core.ApplyTransactionWithEVM(message, api.backend.ChainConfig(), new(core.GasPool).AddGas(message.GasLimit), statedb, vmctx.BlockNumber, txctx.BlockHash, tx, &usedGas, vmenv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("tracing failed: %w", err)
|
return nil, fmt.Errorf("tracing failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ func init() {
|
||||||
tracers.DefaultDirectory.Register("rip7560Validation", newRip7560Tracer, false)
|
tracers.DefaultDirectory.Register("rip7560Validation", newRip7560Tracer, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ValidationFramesMaxCount = 3
|
||||||
|
|
||||||
func newRip7560Tracer(ctx *tracers.Context, cfg json.RawMessage) (*tracers.Tracer, error) {
|
func newRip7560Tracer(ctx *tracers.Context, cfg json.RawMessage) (*tracers.Tracer, error) {
|
||||||
var config prestateTracerConfig
|
var config prestateTracerConfig
|
||||||
if cfg != nil {
|
if cfg != nil {
|
||||||
|
|
@ -22,10 +24,10 @@ func newRip7560Tracer(ctx *tracers.Context, cfg json.RawMessage) (*tracers.Trace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t := &rip7560ValidationTracer{
|
t := &rip7560ValidationTracer{
|
||||||
TraceResults: make([]stateMap, 0),
|
TraceResults: make([]stateMap, ValidationFramesMaxCount),
|
||||||
UsedOpcodes: make([]map[byte]bool, 0),
|
UsedOpcodes: make([]map[string]bool, ValidationFramesMaxCount),
|
||||||
Created: make([]map[common.Address]bool, 0),
|
Created: make([]map[common.Address]bool, ValidationFramesMaxCount),
|
||||||
Deleted: make([]map[common.Address]bool, 0),
|
Deleted: make([]map[common.Address]bool, ValidationFramesMaxCount),
|
||||||
}
|
}
|
||||||
return &tracers.Tracer{
|
return &tracers.Tracer{
|
||||||
Hooks: &tracing.Hooks{
|
Hooks: &tracing.Hooks{
|
||||||
|
|
@ -42,7 +44,7 @@ func newRip7560Tracer(ctx *tracers.Context, cfg json.RawMessage) (*tracers.Trace
|
||||||
type rip7560ValidationTracer struct {
|
type rip7560ValidationTracer struct {
|
||||||
env *tracing.VMContext
|
env *tracing.VMContext
|
||||||
TraceResults []stateMap `json:"traceResults"`
|
TraceResults []stateMap `json:"traceResults"`
|
||||||
UsedOpcodes []map[byte]bool `json:"usedOpcodes"`
|
UsedOpcodes []map[string]bool `json:"usedOpcodes"`
|
||||||
Created []map[common.Address]bool `json:"created"`
|
Created []map[common.Address]bool `json:"created"`
|
||||||
Deleted []map[common.Address]bool `json:"deleted"`
|
Deleted []map[common.Address]bool `json:"deleted"`
|
||||||
// todo
|
// todo
|
||||||
|
|
@ -58,7 +60,12 @@ func (t *rip7560ValidationTracer) OnTxEnd(receipt *types.Receipt, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *rip7560ValidationTracer) OnOpcode(pc uint64, opcode byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
|
func (t *rip7560ValidationTracer) OnOpcode(pc uint64, opcode byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
|
||||||
fmt.Printf("%s %d %d", vm.OpCode(opcode).String(), cost, depth)
|
opcodeName := vm.OpCode(opcode).String()
|
||||||
|
fmt.Printf("%s %d %d\n", opcodeName, cost, depth)
|
||||||
|
if t.UsedOpcodes[0] == nil {
|
||||||
|
t.UsedOpcodes[0] = make(map[string]bool)
|
||||||
|
}
|
||||||
|
t.UsedOpcodes[0][opcodeName] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *rip7560ValidationTracer) GetResult() (json.RawMessage, error) {
|
func (t *rip7560ValidationTracer) GetResult() (json.RawMessage, error) {
|
||||||
|
|
|
||||||
|
|
@ -80,8 +80,8 @@ type TransactionArgs struct {
|
||||||
Signature *hexutil.Bytes
|
Signature *hexutil.Bytes
|
||||||
Paymaster *common.Address `json:"paymaster,omitempty"`
|
Paymaster *common.Address `json:"paymaster,omitempty"`
|
||||||
PaymasterData *hexutil.Bytes `json:"paymasterData,omitempty"`
|
PaymasterData *hexutil.Bytes `json:"paymasterData,omitempty"`
|
||||||
Deployer *common.Address `json:"factory,omitempty"`
|
Deployer *common.Address `json:"deployer,omitempty"`
|
||||||
DeployerData *hexutil.Bytes `json:"factoryData,omitempty"`
|
DeployerData *hexutil.Bytes `json:"deployerData,omitempty"`
|
||||||
BuilderFee *hexutil.Big
|
BuilderFee *hexutil.Big
|
||||||
ValidationGas *hexutil.Uint64 `json:"verificationGasLimit"`
|
ValidationGas *hexutil.Uint64 `json:"verificationGasLimit"`
|
||||||
PaymasterGas *hexutil.Uint64 `json:"paymasterVerificationGasLimit"`
|
PaymasterGas *hexutil.Uint64 `json:"paymasterVerificationGasLimit"`
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue