Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prague & Pascal #524

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import (
"crypto/sha256"
"encoding/binary"
"errors"
"github.com/erigontech/erigon-lib/log/v3"
"math/big"

"github.com/erigontech/erigon-lib/log/v3"

"github.com/erigontech/erigon/core/types"
"github.com/erigontech/secp256k1"

Expand Down Expand Up @@ -226,6 +227,37 @@ var PrecompiledContractsPrague = map[libcommon.Address]PrecompiledContract{
libcommon.BytesToAddress([]byte{0x13}): &bls12381MapFp2ToG2{},
}

var PrecompiledContractsPragueForBSC = map[libcommon.Address]PrecompiledContract{
libcommon.BytesToAddress([]byte{0x01}): &ecrecover{},
libcommon.BytesToAddress([]byte{0x02}): &sha256hash{},
libcommon.BytesToAddress([]byte{0x03}): &ripemd160hash{},
libcommon.BytesToAddress([]byte{0x04}): &dataCopy{},
libcommon.BytesToAddress([]byte{0x05}): &bigModExp{eip2565: true},
libcommon.BytesToAddress([]byte{0x06}): &bn256AddIstanbul{},
libcommon.BytesToAddress([]byte{0x07}): &bn256ScalarMulIstanbul{},
libcommon.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{},
libcommon.BytesToAddress([]byte{0x09}): &blake2F{},
libcommon.BytesToAddress([]byte{0x0a}): &pointEvaluation{},
libcommon.BytesToAddress([]byte{0x0b}): &bls12381G1Add{},
libcommon.BytesToAddress([]byte{0x0c}): &bls12381G1Mul{},
libcommon.BytesToAddress([]byte{0x0d}): &bls12381G1MultiExp{},
libcommon.BytesToAddress([]byte{0x0e}): &bls12381G2Add{},
libcommon.BytesToAddress([]byte{0x0f}): &bls12381G2Mul{},
libcommon.BytesToAddress([]byte{0x10}): &bls12381G2MultiExp{},
libcommon.BytesToAddress([]byte{0x11}): &bls12381Pairing{},
libcommon.BytesToAddress([]byte{0x12}): &bls12381MapFpToG1{},
libcommon.BytesToAddress([]byte{0x13}): &bls12381MapFp2ToG2{},

libcommon.BytesToAddress([]byte{100}): &tmHeaderValidate{},
libcommon.BytesToAddress([]byte{101}): &iavlMerkleProofValidatePlato{},
libcommon.BytesToAddress([]byte{102}): &blsSignatureVerify{},
libcommon.BytesToAddress([]byte{103}): &cometBFTLightBlockValidateHertz{},
libcommon.BytesToAddress([]byte{104}): &verifyDoubleSignEvidence{},
libcommon.BytesToAddress([]byte{105}): &secp256k1SignatureRecover{},

libcommon.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{},
}

// PrecompiledContractsHaber contains the default set of pre-compiled Ethereum
// contracts used in the Haber release.
var PrecompiledContractsHaber = map[libcommon.Address]PrecompiledContract{
Expand Down Expand Up @@ -351,6 +383,7 @@ var (
PrecompiledAddressesMoran []libcommon.Address
PrecompiledAddressesNano []libcommon.Address
PrecompiledAddressesPrague []libcommon.Address
PrecompiledAddressesPragueForBSC []libcommon.Address
PrecompiledAddressesNapoli []libcommon.Address
PrecompiledAddressesCancun []libcommon.Address
PrecompiledAddressesCancunForBSC []libcommon.Address
Expand Down Expand Up @@ -413,12 +446,18 @@ func init() {
for k := range PrecompiledContractsPrague {
PrecompiledAddressesPrague = append(PrecompiledAddressesPrague, k)
}
for k := range PrecompiledContractsPragueForBSC {
PrecompiledAddressesPragueForBSC = append(PrecompiledAddressesPragueForBSC, k)
}
}

// ActivePrecompiles returns the precompiles enabled with the current configuration.
func ActivePrecompiles(rules *chain.Rules) []libcommon.Address {
switch {
case rules.IsPrague:
if rules.IsParlia {
return PrecompiledAddressesPragueForBSC
}
return PrecompiledAddressesPrague
case rules.IsNapoli:
return PrecompiledAddressesNapoli
Expand Down
6 changes: 5 additions & 1 deletion core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ func (evm *EVM) precompile(addr libcommon.Address) (PrecompiledContract, bool) {
var precompiles map[libcommon.Address]PrecompiledContract
switch {
case evm.chainRules.IsPrague:
precompiles = PrecompiledContractsPrague
if evm.chainRules.IsParlia {
precompiles = PrecompiledContractsPragueForBSC
} else {
precompiles = PrecompiledContractsPrague
}
case evm.chainRules.IsNapoli:
precompiles = PrecompiledContractsNapoli
case evm.chainRules.IsHaber:
Expand Down
22 changes: 20 additions & 2 deletions erigon-lib/chain/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type Config struct {
HaberTime *big.Int `json:"haberTime,omitempty"`
HaberFixTime *big.Int `json:"haberFixTime,omitempty"`
BohrTime *big.Int `json:"bohrTime,omitempty"`
PascalTime *big.Int `json:"pascalTime,omitempty"`
PragueTime *big.Int `json:"pragueTime,omitempty"`
OsakaTime *big.Int `json:"osakaTime,omitempty"`

Expand Down Expand Up @@ -126,7 +127,7 @@ func (c *Config) String() string {
engine := c.getEngine()

if c.Consensus == ParliaConsensus {
return fmt.Sprintf("{ChainID: %v Ramanujan: %v, Niels: %v, MirrorSync: %v, Bruno: %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, CancunTime %v, HaberTime %v, HaberFixTime %v, c.BohrTime %v, Engine: %v}",
return fmt.Sprintf("{ChainID: %v Ramanujan: %v, Niels: %v, MirrorSync: %v, Bruno: %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, CancunTime %v, HaberTime %v, HaberFixTime %v, c.BohrTime %v, c.PascalTime %v, c.PragueTime %v, Engine: %v}",
c.ChainID,
c.RamanujanBlock,
c.NielsBlock,
Expand All @@ -149,6 +150,8 @@ func (c *Config) String() string {
c.HaberTime,
c.HaberFixTime,
c.BohrTime,
c.PascalTime,
c.PragueTime,
engine,
)
}
Expand Down Expand Up @@ -524,6 +527,20 @@ func (c *Config) IsOnBohr(currentBlockNumber *big.Int, lastBlockTime uint64, cur
return !c.IsBohr(lastBlockNumber.Uint64(), lastBlockTime) && c.IsBohr(currentBlockNumber.Uint64(), currentBlockTime)
}

// IsPascal returns whether time is either equal to the Haber fork time or greater.
func (c *Config) IsPascal(num uint64, time uint64) bool {
return c.IsLondon(num) && isForked(c.PascalTime, time)
}

// IsOnPascal returns whether currentBlockTime is either equal to the HaberFix fork time or greater firstly.
func (c *Config) IsOnPascal(currentBlockNumber *big.Int, lastBlockTime uint64, currentBlockTime uint64) bool {
lastBlockNumber := new(big.Int)
if currentBlockNumber.Cmp(big.NewInt(1)) >= 0 {
lastBlockNumber.Sub(currentBlockNumber, big.NewInt(1))
}
return !c.IsPascal(lastBlockNumber.Uint64(), lastBlockTime) && c.IsPascal(currentBlockNumber.Uint64(), currentBlockTime)
}

// CheckCompatible checks whether scheduled fork transitions have been imported
// with a mismatching chain configuration.
func (c *Config) CheckCompatible(newcfg *Config, height uint64) *ConfigCompatError {
Expand Down Expand Up @@ -763,7 +780,7 @@ type Rules struct {
IsSharding, IsPrague, IsOsaka, IsNapoli bool
IsNano, IsMoran, IsGibbs, IsPlanck, IsLuban, IsPlato, IsHertz bool
IsHertzfix, IsFeynman, IsFeynmanFix, IsParlia, IsAura bool
IsHaber, IsBohr bool
IsHaber, IsBohr, IsPascal bool
}

// Rules ensures c's ChainID is not nil and returns a new Rules instance
Expand Down Expand Up @@ -800,6 +817,7 @@ func (c *Config) Rules(num uint64, time uint64) *Rules {
IsCancun: c.IsCancun(num, time),
IsHaber: c.IsHaber(num, time),
IsBohr: c.IsBohr(num, time),
IsPascal: c.IsPascal(num, time),
IsOsaka: c.IsOsaka(time),
IsAura: c.Aura != nil,
IsParlia: c.Parlia != nil,
Expand Down
520 changes: 296 additions & 224 deletions params/chainspecs/bsc.json

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions params/chainspecs/chapel.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions params/chainspecs/rialto.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"haberTime": 0,
"haberFixTime": 0,
"bohrTime": 0,
"pragueTime": 0,
"pascalTime": 0,
"parlia": {
"DBPath": "",
"InMemory": false,
Expand Down
Loading