Skip to content

Commit

Permalink
feat(*): remove theogony
Browse files Browse the repository at this point in the history
  • Loading branch information
0xHansLee committed Dec 13, 2024
1 parent d53254a commit 597cf22
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 152 deletions.
12 changes: 3 additions & 9 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bufio"
"errors"
"fmt"
"math/big"
"os"
"reflect"
"runtime"
Expand Down Expand Up @@ -185,14 +184,9 @@ func makeFullNode(ctx *cli.Context) *node.Node {
cfg.Eth.Enable4844 = override4844
}

if ctx.IsSet(utils.OverrideStoryTheogony.Name) {
overrideTheogony := big.NewInt(ctx.Int64(utils.OverrideStoryTheogony.Name))
cfg.Eth.OverrideStoryTheogony = overrideTheogony
}

if ctx.IsSet(utils.OverrideStoryDenomTheogony.Name) {
overrideDenomTheogony := ctx.Uint64(utils.OverrideStoryDenomTheogony.Name)
cfg.Eth.OverrideStoryDenomTheogony = &overrideDenomTheogony
if ctx.IsSet(utils.OverrideStoryDenom.Name) {
overrideStoryDenom := ctx.Uint64(utils.OverrideStoryDenom.Name)
cfg.Eth.OverrideStoryDenom = &overrideStoryDenom
}

backend, eth := utils.RegisterEthService(stack, &cfg.Eth)
Expand Down
3 changes: 1 addition & 2 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ var (
utils.BeaconCheckpointFlag,
utils.CollectWitnessFlag,
utils.Override4844Flag,
utils.OverrideStoryTheogony,
utils.OverrideStoryDenomTheogony,
utils.OverrideStoryDenom,
}, utils.NetworkFlags, utils.DatabaseFlags)

rpcFlags = []cli.Flag{
Expand Down
12 changes: 3 additions & 9 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -981,15 +981,9 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
Category: flags.EthCategory,
}

OverrideStoryTheogony = &cli.IntFlag{
Name: "override.theogony",
Usage: "Manually specify the Theogony fork block height, overriding the bundled setting",
Category: flags.EthCategory,
}

OverrideStoryDenomTheogony = &cli.IntFlag{
Name: "override.denomtheogony",
Usage: "Manually specify the Theogony EIP1559 Denominator, overriding the bundled setting",
OverrideStoryDenom = &cli.IntFlag{
Name: "override.storydenom",
Usage: "Manually specify the EIP1559 Denominator for Story, overriding the bundled setting",
Category: flags.EthCategory,
}
)
Expand Down
9 changes: 4 additions & 5 deletions consensus/misc/eip1559/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
}

var (
num = new(big.Int)
denom = new(big.Int)
blockNum = new(big.Int).Add(parent.Number, common.Big1)
num = new(big.Int)
denom = new(big.Int)
)

if parent.GasUsed > parentGasTarget {
Expand All @@ -78,7 +77,7 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
num.SetUint64(parent.GasUsed - parentGasTarget)
num.Mul(num, parent.BaseFee)
num.Div(num, denom.SetUint64(parentGasTarget))
num.Div(num, denom.SetUint64(config.BaseFeeChangeDenominator(blockNum)))
num.Div(num, denom.SetUint64(config.BaseFeeChangeDenominator()))
baseFeeDelta := math.BigMax(num, common.Big1)

return num.Add(parent.BaseFee, baseFeeDelta)
Expand All @@ -88,7 +87,7 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
num.SetUint64(parentGasTarget - parent.GasUsed)
num.Mul(num, parent.BaseFee)
num.Div(num, denom.SetUint64(parentGasTarget))
num.Div(num, denom.SetUint64(config.BaseFeeChangeDenominator(blockNum)))
num.Div(num, denom.SetUint64(config.BaseFeeChangeDenominator()))
baseFee := num.Sub(parent.BaseFee, num)

return math.BigMax(baseFee, common.Big0)
Expand Down
12 changes: 4 additions & 8 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,8 @@ type ChainOverrides struct {
OverrideVerkle *uint64

// For Story
Override4844 bool
OverrideStoryTheogony *big.Int
OverrideStoryDenomTheogony *uint64
Override4844 bool
OverrideStoryDenom *uint64
}

// SetupGenesisBlock writes or updates the genesis block in db.
Expand Down Expand Up @@ -287,11 +286,8 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, g
if overrides != nil && overrides.Override4844 {
config.Enable4844 = overrides.Override4844
}
if overrides != nil && overrides.OverrideStoryTheogony != nil {
config.TheogonyBlock = overrides.OverrideStoryTheogony
}
if overrides != nil && overrides.OverrideStoryDenomTheogony != nil {
config.EIP1559DenomTheogony = overrides.OverrideStoryDenomTheogony
if overrides != nil && overrides.OverrideStoryDenom != nil {
config.StoryEIP1559Denom = overrides.OverrideStoryDenom
}
}
}
Expand Down
23 changes: 1 addition & 22 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,30 +138,14 @@ var PrecompiledContractsPrague = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{0x12}): &bls12381MapG1{},
common.BytesToAddress([]byte{0x13}): &bls12381MapG2{},
common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{},
common.BytesToAddress([]byte{0x01, 0x01}): &ipGraphTheogony{},
common.BytesToAddress([]byte{0x01, 0x01}): &ipGraph{},
}

var PrecompiledContractsBLS = PrecompiledContractsPrague

var PrecompiledContractsVerkle = PrecompiledContractsPrague

var PrecompiledContractsTheogony = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{0x1}): &ecrecover{},
common.BytesToAddress([]byte{0x2}): &sha256hash{},
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
common.BytesToAddress([]byte{0x4}): &dataCopy{},
common.BytesToAddress([]byte{0x5}): &bigModExp{eip2565: true},
common.BytesToAddress([]byte{0x6}): &bn256AddIstanbul{},
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulIstanbul{},
common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{},
common.BytesToAddress([]byte{0x9}): &blake2F{},
common.BytesToAddress([]byte{0xa}): &kzgPointEvaluation{},
common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{},
common.BytesToAddress([]byte{0x01, 0x01}): &ipGraphTheogony{},
}

var (
PrecompiledAddressesTheogony []common.Address
PrecompiledAddressesPrague []common.Address
PrecompiledAddressesCancun []common.Address
PrecompiledAddressesBerlin []common.Address
Expand Down Expand Up @@ -189,16 +173,11 @@ func init() {
for k := range PrecompiledContractsPrague {
PrecompiledAddressesPrague = append(PrecompiledAddressesPrague, k)
}
for k := range PrecompiledContractsTheogony {
PrecompiledAddressesTheogony = append(PrecompiledAddressesTheogony, k)
}
}

// ActivePrecompiles returns the precompiles enabled with the current configuration.
func ActivePrecompiles(rules params.Rules) []common.Address {
switch {
case rules.IsStoryTheogony:
return PrecompiledAddressesTheogony
case rules.IsPrague:
return PrecompiledAddressesPrague
case rules.IsCancun:
Expand Down
2 changes: 0 additions & 2 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ type (
func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
var precompiles map[common.Address]PrecompiledContract
switch {
case evm.chainRules.IsStoryTheogony:
precompiles = PrecompiledContractsTheogony
case evm.chainRules.IsVerkle:
precompiles = PrecompiledContractsVerkle
case evm.chainRules.IsPrague:
Expand Down
62 changes: 3 additions & 59 deletions core/vm/ipgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ func (c *ipGraph) RequiredGas(input []byte) uint64 {

switch {
case bytes.Equal(selector, addParentIpSelector):
return ipGraphWriteGas
args := input[4:]
parentCount := new(big.Int).SetBytes(getData(args, 64, 32))
return ipGraphWriteGas * parentCount.Uint64()
case bytes.Equal(selector, hasParentIpSelector):
return ipGraphReadGas * averageParentIpCount
case bytes.Equal(selector, getParentIpsSelector):
Expand Down Expand Up @@ -608,61 +610,3 @@ func (c *ipGraph) getRoyaltyStackLrp(ipId common.Address, evm *EVM, ipGraphAddre
}
return totalRoyalty
}

type ipGraphTheogony struct {
ipGraph
}

func (c *ipGraphTheogony) RequiredGas(input []byte) uint64 {
// Smart contract function's selector is the first 4 bytes of the input
if len(input) < 4 {
return intrinsicGas
}

selector := input[:4]

switch {
case bytes.Equal(selector, addParentIpSelector):
args := input[4:]
parentCount := new(big.Int).SetBytes(getData(args, 64, 32))
return ipGraphWriteGas * parentCount.Uint64()
case bytes.Equal(selector, hasParentIpSelector):
return ipGraphReadGas * averageParentIpCount
case bytes.Equal(selector, getParentIpsSelector):
return ipGraphReadGas * averageParentIpCount
case bytes.Equal(selector, getParentIpsCountSelector):
return ipGraphReadGas
case bytes.Equal(selector, getAncestorIpsSelector):
return ipGraphReadGas * averageAncestorIpCount * 2
case bytes.Equal(selector, getAncestorIpsCountSelector):
return ipGraphReadGas * averageParentIpCount * 2
case bytes.Equal(selector, hasAncestorIpsSelector):
return ipGraphReadGas * averageAncestorIpCount * 2
case bytes.Equal(selector, setRoyaltySelector):
return ipGraphWriteGas
case bytes.Equal(selector, getRoyaltySelector):
royaltyPolicyKind := new(big.Int).SetBytes(getData(input, 64+4, 32))
if royaltyPolicyKind.Cmp(royaltyPolicyKindLAP) == 0 {
return ipGraphReadGas * (averageAncestorIpCount * 3)
} else if royaltyPolicyKind.Cmp(royaltyPolicyKindLRP) == 0 {
return ipGraphReadGas * (averageAncestorIpCount*2 + 2)
} else {
return intrinsicGas
}
case bytes.Equal(selector, getRoyaltyStackSelector):
royaltyPolicyKind := new(big.Int).SetBytes(getData(input, 32+4, 32))
if royaltyPolicyKind.Cmp(royaltyPolicyKindLAP) == 0 {
return ipGraphReadGas * (averageParentIpCount + 1)
} else if royaltyPolicyKind.Cmp(royaltyPolicyKindLRP) == 0 {
return ipGraphReadGas * (averageAncestorIpCount * 2)
} else {
return intrinsicGas
}
default:
return intrinsicGas
}
}

func (c *ipGraphTheogony) Run(evm *EVM, input []byte) ([]byte, error) {
return c.ipGraph.Run(evm, input)
}
7 changes: 2 additions & 5 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,8 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if config.Enable4844 {
overrides.Override4844 = config.Enable4844
}
if config.OverrideStoryTheogony != nil {
overrides.OverrideStoryTheogony = config.OverrideStoryTheogony
}
if config.OverrideStoryDenomTheogony != nil {
overrides.OverrideStoryDenomTheogony = config.OverrideStoryDenomTheogony
if config.OverrideStoryDenom != nil {
overrides.OverrideStoryDenom = config.OverrideStoryDenom
}
// TODO (MariusVanDerWijden) get rid of shouldPreserve in a follow-up PR
shouldPreserve := func(header *types.Header) bool {
Expand Down
8 changes: 2 additions & 6 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package ethconfig

import (
"errors"
"math/big"
"time"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -171,11 +170,8 @@ type Config struct {
// Enables EIP-4844 blob transaction support
Enable4844 bool

// Override Theogony fork block height
OverrideStoryTheogony *big.Int `toml:",omitempty"`

// Override EIP1559 Denominator for Theogony hardfork
OverrideStoryDenomTheogony *uint64 `toml:",omitempty"`
// Override EIP1559 Denominator for Story
OverrideStoryDenom *uint64 `toml:",omitempty"`
}

// CreateConsensusEngine creates a consensus engine for the given chain config.
Expand Down
32 changes: 7 additions & 25 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ var (
ShanghaiTime: newUint64(0),
CancunTime: newUint64(0),
Enable4844: false,
TheogonyBlock: big.NewInt(0),
EIP1559DenomTheogony: newUint64(24),
StoryEIP1559Denom: newUint64(24),
}

OdysseyChainConfig = &ChainConfig{
Expand All @@ -187,8 +186,7 @@ var (
ShanghaiTime: newUint64(0),
CancunTime: newUint64(0),
Enable4844: false,
TheogonyBlock: big.NewInt(1243000),
EIP1559DenomTheogony: newUint64(24),
StoryEIP1559Denom: newUint64(24),
}

LocalChainConfig = &ChainConfig{
Expand All @@ -210,8 +208,7 @@ var (
ShanghaiTime: newUint64(0),
CancunTime: newUint64(0),
Enable4844: false,
TheogonyBlock: big.NewInt(0),
EIP1559DenomTheogony: newUint64(24),
StoryEIP1559Denom: newUint64(24),
}

// AllEthashProtocolChanges contains every protocol change (EIPs) introduced
Expand Down Expand Up @@ -457,8 +454,7 @@ type ChainConfig struct {
// 4844 Overrides
Enable4844 bool `json:"enable4844,omitempty"`

TheogonyBlock *big.Int `json:"theogonyBlock,omitempty"` // Theogony switch height (nil = no fork, 0 = already on theogony)
EIP1559DenomTheogony *uint64 `json:"eip1559DenomTheogony,omitempty"` // EIP1559 Denominator for Theogony hardfork overrides
StoryEIP1559Denom *uint64 `json:"storyEIP1559Denom,omitempty"` // EIP1559 Denominator for Story
}

// EthashConfig is the consensus engine configs for proof-of-work based sealing.
Expand Down Expand Up @@ -569,9 +565,6 @@ func (c *ChainConfig) Description() string {
if c.VerkleTime != nil {
banner += fmt.Sprintf(" - Verkle: @%-10v\n", *c.VerkleTime)
}
if c.TheogonyBlock != nil {
banner += fmt.Sprintf(" - Theogony: @%-10v\n", *c.TheogonyBlock)
}
return banner
}

Expand Down Expand Up @@ -680,10 +673,6 @@ func (c *ChainConfig) IsEIP4762(num *big.Int, time uint64) bool {
return c.IsVerkle(num, time)
}

func (c *ChainConfig) IsStoryTheogony(num *big.Int) bool {
return isBlockForked(c.TheogonyBlock, num)
}

// CheckCompatible checks whether scheduled fork transitions have been imported
// with a mismatching chain configuration.
func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64, time uint64) *ConfigCompatError {
Expand Down Expand Up @@ -845,16 +834,13 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int,
if isForkTimestampIncompatible(c.VerkleTime, newcfg.VerkleTime, headTimestamp) {
return newTimestampCompatError("Verkle fork timestamp", c.VerkleTime, newcfg.VerkleTime)
}
if isForkBlockIncompatible(c.TheogonyBlock, newcfg.TheogonyBlock, headNumber) {
return newBlockCompatError("Story Theogony fork block", c.TheogonyBlock, newcfg.TheogonyBlock)
}
return nil
}

// BaseFeeChangeDenominator bounds the amount the base fee can change between blocks.
func (c *ChainConfig) BaseFeeChangeDenominator(num *big.Int) uint64 {
if c.IsStoryTheogony(num) && c.EIP1559DenomTheogony != nil && *c.EIP1559DenomTheogony > 0 {
return *c.EIP1559DenomTheogony
func (c *ChainConfig) BaseFeeChangeDenominator() uint64 {
if c.StoryEIP1559Denom != nil && *c.StoryEIP1559Denom > 0 {
return *c.StoryEIP1559Denom
}

return DefaultBaseFeeChangeDenominator
Expand Down Expand Up @@ -1029,8 +1015,6 @@ type Rules struct {
IsBerlin, IsLondon bool
IsMerge, IsShanghai, IsCancun, IsPrague bool
IsVerkle bool
// Story hardforks
IsStoryTheogony bool
}

// Rules ensures c's ChainID is not nil.
Expand Down Expand Up @@ -1061,7 +1045,5 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
IsPrague: isMerge && c.IsPrague(num, timestamp),
IsVerkle: isVerkle,
IsEIP4762: isVerkle,
// Story hardforks
IsStoryTheogony: isMerge && c.IsStoryTheogony(num),
}
}

0 comments on commit 597cf22

Please sign in to comment.