2025-02-05 16:01:17 -06:00
|
|
|
// Copyright 2022 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/>.
|
|
|
|
|
2022-10-05 19:05:43 -05:00
|
|
|
package tracetest
|
|
|
|
|
|
|
|
import (
|
2025-02-20 08:04:35 -06:00
|
|
|
"encoding/json"
|
2024-04-01 07:53:56 -05:00
|
|
|
"math/big"
|
2022-10-05 19:05:43 -05:00
|
|
|
"strings"
|
|
|
|
"unicode"
|
|
|
|
|
2024-04-01 07:53:56 -05:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/common/math"
|
|
|
|
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
|
|
|
|
"github.com/ethereum/go-ethereum/core"
|
2025-02-04 08:43:18 -06:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2024-04-01 07:53:56 -05:00
|
|
|
"github.com/ethereum/go-ethereum/core/vm"
|
|
|
|
|
2022-10-11 02:37:00 -05:00
|
|
|
// Force-load native and js packages, to trigger registration
|
2022-10-05 19:05:43 -05:00
|
|
|
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
|
|
|
|
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
|
|
|
|
)
|
|
|
|
|
|
|
|
// camel converts a snake cased input string into a camel cased output.
|
|
|
|
func camel(str string) string {
|
|
|
|
pieces := strings.Split(str, "_")
|
|
|
|
for i := 1; i < len(pieces); i++ {
|
|
|
|
pieces[i] = string(unicode.ToUpper(rune(pieces[i][0]))) + pieces[i][1:]
|
|
|
|
}
|
|
|
|
return strings.Join(pieces, "")
|
|
|
|
}
|
2024-04-01 07:53:56 -05:00
|
|
|
|
2025-02-20 08:04:35 -06:00
|
|
|
// traceContext defines a context used to construct the block context
|
|
|
|
type traceContext struct {
|
2024-04-01 07:53:56 -05:00
|
|
|
Number math.HexOrDecimal64 `json:"number"`
|
|
|
|
Difficulty *math.HexOrDecimal256 `json:"difficulty"`
|
|
|
|
Time math.HexOrDecimal64 `json:"timestamp"`
|
|
|
|
GasLimit math.HexOrDecimal64 `json:"gasLimit"`
|
|
|
|
Miner common.Address `json:"miner"`
|
|
|
|
BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"`
|
|
|
|
}
|
|
|
|
|
2025-02-20 08:04:35 -06:00
|
|
|
func (c *traceContext) toBlockContext(genesis *core.Genesis) vm.BlockContext {
|
2024-04-01 07:53:56 -05:00
|
|
|
context := vm.BlockContext{
|
|
|
|
CanTransfer: core.CanTransfer,
|
|
|
|
Transfer: core.Transfer,
|
|
|
|
Coinbase: c.Miner,
|
|
|
|
BlockNumber: new(big.Int).SetUint64(uint64(c.Number)),
|
|
|
|
Time: uint64(c.Time),
|
|
|
|
Difficulty: (*big.Int)(c.Difficulty),
|
|
|
|
GasLimit: uint64(c.GasLimit),
|
|
|
|
}
|
|
|
|
if genesis.Config.IsLondon(context.BlockNumber) {
|
|
|
|
context.BaseFee = (*big.Int)(c.BaseFee)
|
|
|
|
}
|
2024-10-23 01:33:14 -05:00
|
|
|
|
|
|
|
if genesis.Config.TerminalTotalDifficulty != nil && genesis.Config.TerminalTotalDifficulty.Sign() == 0 {
|
|
|
|
context.Random = &genesis.Mixhash
|
|
|
|
}
|
|
|
|
|
2024-04-01 07:53:56 -05:00
|
|
|
if genesis.ExcessBlobGas != nil && genesis.BlobGasUsed != nil {
|
2025-02-04 14:43:18 -06:00
|
|
|
header := &types.Header{Number: genesis.Config.LondonBlock, Time: *genesis.Config.CancunTime}
|
2025-02-05 03:35:03 -06:00
|
|
|
excess := eip4844.CalcExcessBlobGas(genesis.Config, header, genesis.Timestamp)
|
2025-02-04 14:43:18 -06:00
|
|
|
header.ExcessBlobGas = &excess
|
2025-02-04 08:43:18 -06:00
|
|
|
context.BlobBaseFee = eip4844.CalcBlobFee(genesis.Config, header)
|
2024-04-01 07:53:56 -05:00
|
|
|
}
|
|
|
|
return context
|
|
|
|
}
|
2025-02-20 08:04:35 -06:00
|
|
|
|
|
|
|
// tracerTestEnv defines a tracer test required fields
|
|
|
|
type tracerTestEnv struct {
|
|
|
|
Genesis *core.Genesis `json:"genesis"`
|
|
|
|
Context *traceContext `json:"context"`
|
|
|
|
Input string `json:"input"`
|
|
|
|
TracerConfig json.RawMessage `json:"tracerConfig"`
|
|
|
|
}
|