Skip to content

Commit

Permalink
feat(*): remove theogony (#78)
Browse files Browse the repository at this point in the history
* feat(*): remove theogony

* chore(network): change to use const for denom

* chore(network): define story param

* chore(params): fix typo
  • Loading branch information
0xHansLee authored Dec 13, 2024
1 parent d53254a commit f738866
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 161 deletions.
11 changes: 0 additions & 11 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,16 +184,6 @@ 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
}

backend, eth := utils.RegisterEthService(stack, &cfg.Eth)

// Create gauge with geth system and build information
Expand Down
2 changes: 0 additions & 2 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ var (
utils.BeaconCheckpointFlag,
utils.CollectWitnessFlag,
utils.Override4844Flag,
utils.OverrideStoryTheogony,
utils.OverrideStoryDenomTheogony,
}, utils.NetworkFlags, utils.DatabaseFlags)

rpcFlags = []cli.Flag{
Expand Down
12 changes: 0 additions & 12 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,18 +980,6 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
Usage: "Enable 4844 blob transactions",
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",
Category: flags.EthCategory,
}
)

var (
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
10 changes: 1 addition & 9 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,7 @@ type ChainOverrides struct {
OverrideVerkle *uint64

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

// SetupGenesisBlock writes or updates the genesis block in db.
Expand Down Expand Up @@ -287,12 +285,6 @@ 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
}
}
}
// Just commit the new block if there is no stored genesis block.
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)
}
6 changes: 0 additions & 6 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,6 @@ 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
}
// TODO (MariusVanDerWijden) get rid of shouldPreserve in a follow-up PR
shouldPreserve := func(header *types.Header) bool {
return false
Expand Down
7 changes: 0 additions & 7 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 @@ -170,12 +169,6 @@ 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"`
}

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

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

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

// AllEthashProtocolChanges contains every protocol change (EIPs) introduced
Expand Down Expand Up @@ -456,9 +450,6 @@ 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
}

// EthashConfig is the consensus engine configs for proof-of-work based sealing.
Expand Down Expand Up @@ -569,9 +560,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 +668,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 +829,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.IsStory() {
return DefaultBaseFeeChangeDenomStoryHomer
}

return DefaultBaseFeeChangeDenominator
Expand All @@ -870,6 +851,14 @@ func (c *ChainConfig) Is4844Enabled() bool {
return c.Enable4844
}

func (c *ChainConfig) IsStory() bool {
chainId := c.ChainID.Uint64()
return chainId == IDStoryMainnet ||
chainId == IDStoryIliad ||
chainId == IDStoryOdyssey ||
chainId == IDStoryLocal
}

// LatestFork returns the latest time-based fork that would be active for the given time.
func (c *ChainConfig) LatestFork(time uint64) forks.Fork {
// Assume last non-time-based fork has passed.
Expand Down Expand Up @@ -1029,8 +1018,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 +1048,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),
}
}
Loading

0 comments on commit f738866

Please sign in to comment.