Skip to content

Commit de5160c

Browse files
feat: remove the restriction on pre-compile (#177)
* feat: remove the restriction on pre-compile & restore results of opcode BLOCKHASH * revert opcode blockhash * rename version name * rename vars * rename vars * add fork time check * revert kzgPointEvaluation * change byte format * config string() * remove darwin * remove duplicated code --------- Co-authored-by: FletcherMan <[email protected]>
1 parent a26e7b1 commit de5160c

9 files changed

+72
-54
lines changed

core/blockchain_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3520,7 +3520,7 @@ func TestCurieTransition(t *testing.T) {
35203520
b, _ := json.Marshal(params.AllEthashProtocolChanges)
35213521
json.Unmarshal(b, &config)
35223522
config.CurieBlock = big.NewInt(2)
3523-
config.DarwinTime = nil
3523+
config.Morph203Time = nil
35243524

35253525
var (
35263526
db = rawdb.NewMemoryDatabase()

core/state_processor_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestStateProcessorErrors(t *testing.T) {
5858
ShanghaiBlock: big.NewInt(0),
5959
BernoulliBlock: big.NewInt(0),
6060
CurieBlock: big.NewInt(0),
61-
DarwinTime: new(uint64),
61+
Morph203Time: new(uint64),
6262
Ethash: new(params.EthashConfig),
6363
}
6464
signer = types.LatestSigner(config)

core/vm/contracts.go

+21-11
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ import (
3535
)
3636

3737
var (
38-
errPrecompileDisabled = errors.New("sha256, ripemd160, blake2f precompiles temporarily disabled")
39-
errModexpUnsupportedInput = errors.New("modexp temporarily only accepts inputs of 32 bytes (256 bits) or less")
38+
errPrecompileDisabled = errors.New("sha256, ripemd160, blake2f precompiles temporarily disabled")
4039
)
4140

4241
// PrecompiledContract is the basic interface for native Go contracts. The implementation
@@ -125,6 +124,20 @@ var PrecompiledContractsBernoulli = map[common.Address]PrecompiledContract{
125124
common.BytesToAddress([]byte{9}): &blake2FDisabled{},
126125
}
127126

127+
// PrecompiledContractsMorph203 contains the default set of pre-compiled Ethereum
128+
// contracts used in the Morph203 release.
129+
var PrecompiledContractsMorph203 = map[common.Address]PrecompiledContract{
130+
common.BytesToAddress([]byte{1}): &ecrecover{},
131+
common.BytesToAddress([]byte{2}): &sha256hash{},
132+
common.BytesToAddress([]byte{3}): &ripemd160hash{},
133+
common.BytesToAddress([]byte{4}): &dataCopy{},
134+
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true},
135+
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
136+
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
137+
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
138+
common.BytesToAddress([]byte{9}): &blake2F{},
139+
}
140+
128141
// PrecompiledContractsBLS contains the set of pre-compiled Ethereum
129142
// contracts specified in EIP-2537. These are exported for testing purposes.
130143
var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{
@@ -140,6 +153,7 @@ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{
140153
}
141154

142155
var (
156+
PrecompiledAddressesMorph203 []common.Address
143157
PrecompiledAddressesBernoulli []common.Address
144158
PrecompiledAddressesArchimedes []common.Address
145159
PrecompiledAddressesBerlin []common.Address
@@ -167,11 +181,16 @@ func init() {
167181
for k := range PrecompiledContractsBernoulli {
168182
PrecompiledAddressesBernoulli = append(PrecompiledAddressesBernoulli, k)
169183
}
184+
for k := range PrecompiledContractsMorph203 {
185+
PrecompiledAddressesMorph203 = append(PrecompiledAddressesMorph203, k)
186+
}
170187
}
171188

172189
// ActivePrecompiles returns the precompiles enabled with the current configuration.
173190
func ActivePrecompiles(rules params.Rules) []common.Address {
174191
switch {
192+
case rules.IsMorph203:
193+
return PrecompiledAddressesMorph203
175194
case rules.IsBernoulli:
176195
return PrecompiledAddressesBernoulli
177196
case rules.IsArchimedes:
@@ -437,11 +456,6 @@ func (c *bigModExp) Run(input []byte) ([]byte, error) {
437456
expLen = expLenBigInt.Uint64()
438457
modLen = modLenBigInt.Uint64()
439458
)
440-
// Check that all inputs are `u256` (32 - bytes) or less, revert otherwise
441-
var lenLimit = new(big.Int).SetInt64(32)
442-
if baseLenBigInt.Cmp(lenLimit) > 0 || expLenBigInt.Cmp(lenLimit) > 0 || modLenBigInt.Cmp(lenLimit) > 0 {
443-
return nil, errModexpUnsupportedInput
444-
}
445459
if len(input) > 96 {
446460
input = input[96:]
447461
} else {
@@ -578,10 +592,6 @@ var (
578592
// runBn256Pairing implements the Bn256Pairing precompile, referenced by both
579593
// Byzantium and Istanbul operations.
580594
func runBn256Pairing(input []byte) ([]byte, error) {
581-
// Allow at most 4 inputs
582-
if len(input) > 4*192 {
583-
return nil, errBadPairingInput
584-
}
585595
// Handle some corner cases cheaply
586596
if len(input)%192 > 0 {
587597
return nil, errBadPairingInput

core/vm/interpreter.go

-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
7474
if cfg.JumpTable[STOP] == nil {
7575
var jt JumpTable
7676
switch {
77-
case evm.chainRules.IsDarwin:
78-
jt = darwinInstructionSet
7977
case evm.chainRules.IsCurie:
8078
jt = curieInstructionSet
8179
case evm.chainRules.IsShanghai:

core/vm/jump_table.go

-8
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,11 @@ var (
6060
londonInstructionSet = newLondonInstructionSet()
6161
shanghaiInstructionSet = newShanghaiInstructionSet()
6262
curieInstructionSet = newCurieInstructionSet()
63-
darwinInstructionSet = newDarwinInstructionSet()
6463
)
6564

6665
// JumpTable contains the EVM opcodes supported at a given fork.
6766
type JumpTable [256]*operation
6867

69-
// newDarwinInstructionSet returns the frontier, homestead, byzantium,
70-
// contantinople, istanbul, petersburg, berlin, london, shanghai, curie, and darwin instructions.
71-
func newDarwinInstructionSet() JumpTable {
72-
instructionSet := newCurieInstructionSet()
73-
return instructionSet
74-
}
75-
7668
// newCurieInstructionSet returns the frontier, homestead, byzantium,
7769
// contantinople, istanbul, petersburg, berlin, london, shanghai, and curie instructions.
7870
func newCurieInstructionSet() JumpTable {

core/vm/runtime/runtime.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func setDefaults(cfg *Config) {
7272
ShanghaiBlock: new(big.Int),
7373
BernoulliBlock: new(big.Int),
7474
CurieBlock: new(big.Int),
75-
DarwinTime: new(uint64),
75+
Morph203Time: new(uint64),
7676
}
7777
}
7878

eth/gasprice/gasprice_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, pending bool) *testBacke
114114
config.ShanghaiBlock = londonBlock
115115
config.BernoulliBlock = londonBlock
116116
config.CurieBlock = londonBlock
117-
config.DarwinTime = nil
117+
config.Morph203Time = nil
118118
engine := ethash.NewFaker()
119119
db := rawdb.NewMemoryDatabase()
120120
genesis, err := gspec.Commit(db)

params/config.go

+44-26
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ var (
281281
ShanghaiBlock: big.NewInt(0),
282282
BernoulliBlock: big.NewInt(0),
283283
CurieBlock: big.NewInt(6330180),
284-
DarwinTime: nil,
284+
Morph203Time: nil,
285285
TerminalTotalDifficulty: big.NewInt(0),
286286
Morph: MorphConfig{
287287
UseZktrie: true,
@@ -311,7 +311,7 @@ var (
311311
ShanghaiBlock: big.NewInt(0),
312312
BernoulliBlock: big.NewInt(0),
313313
CurieBlock: big.NewInt(0),
314-
DarwinTime: nil,
314+
Morph203Time: nil,
315315
TerminalTotalDifficulty: big.NewInt(0),
316316
Morph: MorphConfig{
317317
UseZktrie: true,
@@ -347,7 +347,7 @@ var (
347347
ShanghaiBlock: big.NewInt(0),
348348
BernoulliBlock: big.NewInt(0),
349349
CurieBlock: big.NewInt(0),
350-
DarwinTime: new(uint64),
350+
Morph203Time: new(uint64),
351351
TerminalTotalDifficulty: nil,
352352
Ethash: new(EthashConfig),
353353
Clique: nil,
@@ -383,7 +383,7 @@ var (
383383
ShanghaiBlock: big.NewInt(0),
384384
BernoulliBlock: big.NewInt(0),
385385
CurieBlock: big.NewInt(0),
386-
DarwinTime: new(uint64),
386+
Morph203Time: new(uint64),
387387
TerminalTotalDifficulty: nil,
388388
Ethash: nil,
389389
Clique: &CliqueConfig{Period: 0, Epoch: 30000},
@@ -414,7 +414,7 @@ var (
414414
ShanghaiBlock: big.NewInt(0),
415415
BernoulliBlock: big.NewInt(0),
416416
CurieBlock: big.NewInt(0),
417-
DarwinTime: new(uint64),
417+
Morph203Time: new(uint64),
418418
TerminalTotalDifficulty: nil,
419419
Ethash: new(EthashConfig),
420420
Clique: nil,
@@ -446,7 +446,7 @@ var (
446446
ShanghaiBlock: big.NewInt(0),
447447
BernoulliBlock: big.NewInt(0),
448448
CurieBlock: big.NewInt(0),
449-
DarwinTime: new(uint64),
449+
Morph203Time: new(uint64),
450450
TerminalTotalDifficulty: nil,
451451
Ethash: new(EthashConfig),
452452
Clique: nil,
@@ -537,7 +537,7 @@ type ChainConfig struct {
537537
ShanghaiBlock *big.Int `json:"shanghaiBlock,omitempty"` // Shanghai switch block (nil = no fork, 0 = already on shanghai)
538538
BernoulliBlock *big.Int `json:"bernoulliBlock,omitempty"` // Bernoulli switch block (nil = no fork, 0 = already on bernoulli)
539539
CurieBlock *big.Int `json:"curieBlock,omitempty"` // Curie switch block (nil = no fork, 0 = already on curie)
540-
DarwinTime *uint64 `json:"darwinTime,omitempty"` // Darwin switch time (nil = no fork, 0 = already on darwin)
540+
Morph203Time *uint64 `json:"morph203Time,omitempty"` // Morph203Time switch time (nil = no fork, 0 = already on morph203)
541541

542542
// TerminalTotalDifficulty is the amount of total difficulty reached by
543543
// the network that triggers the consensus upgrade.
@@ -630,7 +630,7 @@ func (c *ChainConfig) String() string {
630630
default:
631631
engine = "unknown"
632632
}
633-
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, Berlin: %v, London: %v, Arrow Glacier: %v, Archimedes: %v, Shanghai: %v, Bernoulli: %v, Curie: %v, Darwin: %v, Engine: %v, Morph config: %v}",
633+
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, Berlin: %v, London: %v, Arrow Glacier: %v, Archimedes: %v, Shanghai: %v, Bernoulli: %v, Curie: %v, Morph203: %v, Engine: %v, Morph config: %v}",
634634
c.ChainID,
635635
c.HomesteadBlock,
636636
c.DAOForkBlock,
@@ -650,7 +650,7 @@ func (c *ChainConfig) String() string {
650650
c.ShanghaiBlock,
651651
c.BernoulliBlock,
652652
c.CurieBlock,
653-
c.DarwinTime,
653+
c.Morph203Time,
654654
engine,
655655
c.Morph,
656656
)
@@ -743,9 +743,9 @@ func (c *ChainConfig) IsCurie(num *big.Int) bool {
743743
return isForked(c.CurieBlock, num)
744744
}
745745

746-
// IsDarwin returns whether num is either equal to the Darwin fork block or greater.
747-
func (c *ChainConfig) IsDarwin(now uint64) bool {
748-
return isForkedTime(now, c.DarwinTime)
746+
// IsMorph203 returns whether num is either equal to the Morph203 fork block or greater.
747+
func (c *ChainConfig) IsMorph203(now uint64) bool {
748+
return isForkedTime(now, c.Morph203Time)
749749
}
750750

751751
// IsTerminalPoWBlock returns whether the given block is the last block of PoW stage.
@@ -778,9 +778,10 @@ func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64) *Confi
778778
// to guarantee that forks can be implemented in a different order than on official networks
779779
func (c *ChainConfig) CheckConfigForkOrder() error {
780780
type fork struct {
781-
name string
782-
block *big.Int
783-
optional bool // if true, the fork may be nil and next fork is still allowed
781+
name string
782+
block *big.Int
783+
timestamp *uint64 // forks after the merge are scheduled using timestamps
784+
optional bool // if true, the fork may be nil and next fork is still allowed
784785
}
785786
var lastFork fork
786787
for _, cur := range []fork{
@@ -801,22 +802,39 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
801802
{name: "shanghaiBlock", block: c.ShanghaiBlock, optional: true},
802803
{name: "bernoulliBlock", block: c.BernoulliBlock, optional: true},
803804
{name: "curieBlock", block: c.CurieBlock, optional: true},
805+
{name: "morph203Time", timestamp: c.Morph203Time, optional: true},
804806
} {
805807
if lastFork.name != "" {
806-
// Next one must be higher number
807-
if lastFork.block == nil && cur.block != nil {
808-
return fmt.Errorf("unsupported fork ordering: %v not enabled, but %v enabled at %v",
809-
lastFork.name, cur.name, cur.block)
810-
}
811-
if lastFork.block != nil && cur.block != nil {
812-
if lastFork.block.Cmp(cur.block) > 0 {
813-
return fmt.Errorf("unsupported fork ordering: %v enabled at %v, but %v enabled at %v",
808+
switch {
809+
// Non-optional forks must all be present in the chain config up to the last defined fork
810+
case lastFork.block == nil && lastFork.timestamp == nil && (cur.block != nil || cur.timestamp != nil):
811+
if cur.block != nil {
812+
return fmt.Errorf("unsupported fork ordering: %v not enabled, but %v enabled at block %v",
813+
lastFork.name, cur.name, cur.block)
814+
} else {
815+
return fmt.Errorf("unsupported fork ordering: %v not enabled, but %v enabled at timestamp %v",
816+
lastFork.name, cur.name, *cur.timestamp)
817+
}
818+
819+
// Fork (whether defined by block or timestamp) must follow the fork definition sequence
820+
case (lastFork.block != nil && cur.block != nil) || (lastFork.timestamp != nil && cur.timestamp != nil):
821+
if lastFork.block != nil && lastFork.block.Cmp(cur.block) > 0 {
822+
return fmt.Errorf("unsupported fork ordering: %v enabled at block %v, but %v enabled at block %v",
814823
lastFork.name, lastFork.block, cur.name, cur.block)
824+
} else if lastFork.timestamp != nil && *lastFork.timestamp > *cur.timestamp {
825+
return fmt.Errorf("unsupported fork ordering: %v enabled at timestamp %v, but %v enabled at timestamp %v",
826+
lastFork.name, *lastFork.timestamp, cur.name, *cur.timestamp)
827+
}
828+
829+
// Timestamp based forks can follow block based ones, but not the other way around
830+
if lastFork.timestamp != nil && cur.block != nil {
831+
return fmt.Errorf("unsupported fork ordering: %v used timestamp ordering, but %v reverted to block ordering",
832+
lastFork.name, cur.name)
815833
}
816834
}
817835
}
818836
// If it was optional and not set, then ignore it
819-
if !cur.optional || cur.block != nil {
837+
if !cur.optional || (cur.block != nil || cur.timestamp != nil) {
820838
lastFork = cur
821839
}
822840
}
@@ -960,7 +978,7 @@ type Rules struct {
960978
IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool
961979
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
962980
IsBerlin, IsLondon, IsArchimedes, IsShanghai bool
963-
IsBernoulli, IsCurie, IsDarwin bool
981+
IsBernoulli, IsCurie, IsMorph203 bool
964982
}
965983

966984
// Rules ensures c's ChainID is not nil.
@@ -985,6 +1003,6 @@ func (c *ChainConfig) Rules(num *big.Int, time uint64) Rules {
9851003
IsShanghai: c.IsShanghai(num),
9861004
IsBernoulli: c.IsBernoulli(num),
9871005
IsCurie: c.IsCurie(num),
988-
IsDarwin: c.IsDarwin(time),
1006+
IsMorph203: c.IsMorph203(time),
9891007
}
9901008
}

params/version.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import (
2222
)
2323

2424
const (
25-
VersionMajor = 5 // Major version component of the current release
26-
VersionMinor = 5 // Minor version component of the current release
27-
VersionPatch = 1 // Patch version component of the current release
25+
VersionMajor = 2 // Major version component of the current release
26+
VersionMinor = 0 // Minor version component of the current release
27+
VersionPatch = 3 // Patch version component of the current release
2828
VersionMeta = "mainnet" // Version metadata to append to the version string
2929
)
3030

0 commit comments

Comments
 (0)