Skip to content

Commit

Permalink
core/vm: add PrecompiledContractsTycho
Browse files Browse the repository at this point in the history
  • Loading branch information
buddh0 committed Mar 20, 2024
1 parent 10ae179 commit b3e3ead
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
29 changes: 25 additions & 4 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,26 @@ var PrecompiledContractsCancun = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
common.BytesToAddress([]byte{9}): &blake2F{},
common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{},
}

// PrecompiledContractsTycho contains the default set of pre-compiled Ethereum
// contracts used in the Tycho release.
var PrecompiledContractsTycho = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{1}): &ecrecover{},
common.BytesToAddress([]byte{2}): &sha256hash{},
common.BytesToAddress([]byte{3}): &ripemd160hash{},
common.BytesToAddress([]byte{4}): &dataCopy{},
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true},
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
common.BytesToAddress([]byte{9}): &blake2F{},
common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{},

common.BytesToAddress([]byte{100}): &tmHeaderValidate{},
common.BytesToAddress([]byte{101}): &iavlMerkleProofValidatePlato{},
common.BytesToAddress([]byte{102}): &blsSignatureVerify{},
common.BytesToAddress([]byte{103}): &cometBFTLightBlockValidate{},
common.BytesToAddress([]byte{103}): &cometBFTLightBlockValidateHertz{},
common.BytesToAddress([]byte{104}): &verifyDoubleSignEvidence{},
common.BytesToAddress([]byte{105}): &secp256k1SignatureRecover{},
}
Expand Down Expand Up @@ -262,7 +277,9 @@ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{
}

var (
PrecompiledAddressesTycho []common.Address
PrecompiledAddressesCancun []common.Address
PrecompiledAddressesFeynman []common.Address
PrecompiledAddressesHertz []common.Address
PrecompiledAddressesPlato []common.Address
PrecompiledAddressesLuban []common.Address
Expand All @@ -273,7 +290,6 @@ var (
PrecompiledAddressesIstanbul []common.Address
PrecompiledAddressesByzantium []common.Address
PrecompiledAddressesHomestead []common.Address
PrecompiledAddressesFeynman []common.Address
)

func init() {
Expand Down Expand Up @@ -307,17 +323,22 @@ func init() {
for k := range PrecompiledContractsHertz {
PrecompiledAddressesHertz = append(PrecompiledAddressesHertz, k)
}
for k := range PrecompiledContractsFeynman {
PrecompiledAddressesFeynman = append(PrecompiledAddressesFeynman, k)
}
for k := range PrecompiledContractsCancun {
PrecompiledAddressesCancun = append(PrecompiledAddressesCancun, k)
}
for k := range PrecompiledContractsFeynman {
PrecompiledAddressesFeynman = append(PrecompiledAddressesFeynman, k)
for k := range PrecompiledContractsTycho {
PrecompiledAddressesTycho = append(PrecompiledAddressesTycho, k)
}
}

// ActivePrecompiles returns the precompiles enabled with the current configuration.
func ActivePrecompiles(rules params.Rules) []common.Address {
switch {
case rules.IsTycho:
return PrecompiledAddressesTycho
case rules.IsCancun:
return PrecompiledAddressesCancun
case rules.IsFeynman:
Expand Down
2 changes: 2 additions & 0 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type (
func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
var precompiles map[common.Address]PrecompiledContract
switch {
case evm.chainRules.IsTycho:
precompiles = PrecompiledContractsTycho
case evm.chainRules.IsCancun:
precompiles = PrecompiledContractsCancun
case evm.chainRules.IsFeynman:
Expand Down
21 changes: 19 additions & 2 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ type ChainConfig struct {
FeynmanTime *uint64 `json:"feynmanTime,omitempty"` // Feynman switch time (nil = no fork, 0 = already activated)
FeynmanFixTime *uint64 `json:"feynmanFixTime,omitempty"` // FeynmanFix switch time (nil = no fork, 0 = already activated)
CancunTime *uint64 `json:"cancunTime,omitempty"` // Cancun switch time (nil = no fork, 0 = already on cancun)
TychoTime *uint64 `json:"TychoTime,omitempty"` // Cancun switch time (nil = no fork, 0 = already on tycho)
PragueTime *uint64 `json:"pragueTime,omitempty"` // Prague switch time (nil = no fork, 0 = already on prague)
VerkleTime *uint64 `json:"verkleTime,omitempty"` // Verkle switch time (nil = no fork, 0 = already on verkle)

Expand Down Expand Up @@ -598,7 +599,12 @@ func (c *ChainConfig) String() string {
FeynmanFixTime = big.NewInt(0).SetUint64(*c.FeynmanFixTime)
}

return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Ramanujan: %v, Niels: %v, MirrorSync: %v, Bruno: %v, Berlin: %v, YOLO v3: %v, CatalystBlock: %v, London: %v, ArrowGlacier: %v, MergeFork:%v, Euler: %v, Gibbs: %v, Nano: %v, Moran: %v, Planck: %v,Luban: %v, Plato: %v, Hertz: %v, Hertzfix: %v, ShanghaiTime: %v, KeplerTime: %v, FeynmanTime: %v, FeynmanFixTime: %v, Engine: %v}",
var TychoTime *big.Int
if c.TychoTime != nil {
TychoTime = big.NewInt(0).SetUint64(*c.TychoTime)
}

return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Ramanujan: %v, Niels: %v, MirrorSync: %v, Bruno: %v, Berlin: %v, YOLO v3: %v, CatalystBlock: %v, London: %v, ArrowGlacier: %v, MergeFork:%v, Euler: %v, Gibbs: %v, Nano: %v, Moran: %v, Planck: %v,Luban: %v, Plato: %v, Hertz: %v, Hertzfix: %v, ShanghaiTime: %v, KeplerTime: %v, FeynmanTime: %v, FeynmanFixTime: %v, TychoTime: %v, Engine: %v}",
c.ChainID,
c.HomesteadBlock,
c.DAOForkBlock,
Expand Down Expand Up @@ -634,6 +640,7 @@ func (c *ChainConfig) String() string {
KeplerTime,
FeynmanTime,
FeynmanFixTime,
TychoTime,
engine,
)
}
Expand Down Expand Up @@ -901,6 +908,11 @@ func (c *ChainConfig) IsCancun(num *big.Int, time uint64) bool {
return c.IsLondon(num) && isTimestampForked(c.CancunTime, time)
}

// IsTycho returns whether num is either equal to the Tycho fork time or greater.
func (c *ChainConfig) IsTycho(num *big.Int, time uint64) bool {
return c.IsLondon(num) && isTimestampForked(c.TychoTime, time)
}

// IsPrague returns whether num is either equal to the Prague fork time or greater.
func (c *ChainConfig) IsPrague(num *big.Int, time uint64) bool {
return c.IsLondon(num) && isTimestampForked(c.PragueTime, time)
Expand Down Expand Up @@ -1287,7 +1299,10 @@ type Rules struct {
IsPlato bool
IsHertz bool
IsHertzfix bool
IsShanghai, IsKepler, IsFeynman, IsCancun, IsPrague bool
IsShanghai, IsKepler bool
IsFeynman, IsFeynmanFix bool
IsCancun, IsTycho bool
IsPrague bool
IsVerkle bool
}

Expand Down Expand Up @@ -1322,7 +1337,9 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
IsShanghai: c.IsShanghai(num, timestamp),
IsKepler: c.IsKepler(num, timestamp),
IsFeynman: c.IsFeynman(num, timestamp),
IsFeynmanFix: c.IsFeynmanFix(num, timestamp),
IsCancun: c.IsCancun(num, timestamp),
IsTycho: c.IsTycho(num, timestamp),
IsPrague: c.IsPrague(num, timestamp),
IsVerkle: c.IsVerkle(num, timestamp),
}
Expand Down
4 changes: 0 additions & 4 deletions tests/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,6 @@ func (tm *testMatcher) runTestFile(t *testing.T, path, name string, runTest inte
if r, _ := tm.findSkip(name); r != "" {
t.Skip(r)
}
// TODO(Nathan): fix before enable Cancun
if strings.Contains(key, "Cancun") {
return
}
runTestFunc(runTest, t, name, m, key)
})
}
Expand Down

0 comments on commit b3e3ead

Please sign in to comment.