Skip to content

Commit

Permalink
don't set poststate after forkid8 (#185)
Browse files Browse the repository at this point in the history
* don't set poststate after forkid8

* add forkid8 name
  • Loading branch information
V-Staykov authored Mar 12, 2024
1 parent 063a381 commit bccf530
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 40 deletions.
22 changes: 11 additions & 11 deletions chain/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (
ForkID5Dragonfruit = 5
ForkID6IncaBerry = 6
ForkID7Etrog = 7
ForkID8 = 8
ForkID88Elderberry = 8
)

// Config is the core config which determines the blockchain settings.
Expand Down Expand Up @@ -88,7 +88,7 @@ type Config struct {
ForkID5DragonfruitBlock *big.Int `json:"forkID5DragonfruitBlock,omitempty"`
ForkID6IncaBerryBlock *big.Int `json:"forkID6IncaBerryBlock,omitempty"`
ForkID7EtrogBlock *big.Int `json:"forkID7EtrogBlock,omitempty"`
ForkID8Block *big.Int `json:"forkID8EtrogBlock,omitempty"`
ForkID88ElderberryBlock *big.Int `json:"forkID88ElderberryBlock,omitempty"`
}

func (c *Config) String() string {
Expand Down Expand Up @@ -235,8 +235,8 @@ func (c *Config) IsForkID7Etrog(num uint64) bool {
return isForked(c.ForkID7EtrogBlock, num)
}

func (c *Config) IsForkID8(num uint64) bool {
return isForked(c.ForkID8Block, num)
func (c *Config) IsForkID8Elderberry(num uint64) bool {
return isForked(c.ForkID88ElderberryBlock, num)
}

// CheckCompatible checks whether scheduled fork transitions have been imported
Expand Down Expand Up @@ -408,12 +408,12 @@ func newCompatError(what string, storedblock, newblock *big.Int) *chain.ConfigCo
// Rules is a one time interface meaning that it shouldn't be used in between transition
// phases.
type Rules struct {
ChainID *big.Int
IsHomestead, IsTangerineWhistle, IsSpuriousDragon bool
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
IsBerlin, IsLondon, IsShanghai, IsCancun, IsPrague bool
IsEip1559FeeCollector, IsAura bool
IsForkID4, IsForkID5Dragonfruit, IsForkID6IncaBerry, IsForkID7Etrog, IsForkID8 bool
ChainID *big.Int
IsHomestead, IsTangerineWhistle, IsSpuriousDragon bool
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
IsBerlin, IsLondon, IsShanghai, IsCancun, IsPrague bool
IsEip1559FeeCollector, IsAura bool
IsForkID4, IsForkID5Dragonfruit, IsForkID6IncaBerry, IsForkID7Etrog, IsForkID8Elderberry bool
}

// Rules ensures c's ChainID is not nil and returns a new Rules instance
Expand Down Expand Up @@ -443,7 +443,7 @@ func (c *Config) Rules(num uint64, time uint64) *Rules {
IsForkID5Dragonfruit: c.IsForkID5Dragonfruit(num),
IsForkID6IncaBerry: c.IsForkID6IncaBerry(num),
IsForkID7Etrog: c.IsForkID7Etrog(num),
IsForkID8: c.IsForkID8(num),
IsForkID8Elderberry: c.IsForkID8Elderberry(num),
}
}

Expand Down
28 changes: 15 additions & 13 deletions core/blockchain_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func ExecuteBlockEphemerallyZk(
blockGasLimit := block.GasLimit()

//[hack] - on forkid7 this gas limit was used for execution but rpc is now returning forkid8 gas limit
if !chainConfig.IsForkID8(block.NumberU64()) {
if !chainConfig.IsForkID8Elderberry(block.NumberU64()) {
blockGasLimit = 18446744073709551615
}

Expand Down Expand Up @@ -202,19 +202,21 @@ func ExecuteBlockEphemerallyZk(
return nil, err
}

// the stateroot in the transactions that comes from the datastream
// is the one after smart contract writes so it can't be used
// but since pre forkid7 blocks have 1 tx only, we can use the block root
if chainConfig.IsForkID7Etrog(blockNum) {
receipt.PostState = intermediateState.Bytes()
} else {
receipt.PostState = header.Root.Bytes()
}
// forkid8 tje poststate is empty
// forkid8 also fixed the bugs with logs and cumulative gas used
if !chainConfig.IsForkID8Elderberry(blockNum) {
// the stateroot in the transactions that comes from the datastream
// is the one after smart contract writes so it can't be used
// but since pre forkid7 blocks have 1 tx only, we can use the block root
if chainConfig.IsForkID7Etrog(blockNum) {
receipt.PostState = intermediateState.Bytes()
} else {
receipt.PostState = header.Root.Bytes()
}

//[hack] log0 pre forkid8 are not included in the rpc logs
// also pre forkid8 comulative gas used is same as gas used
var fixedLogs types.Logs
if !chainConfig.IsForkID8(blockNum) {
//[hack] log0 pre forkid8 are not included in the rpc logs
// also pre forkid8 comulative gas used is same as gas used
var fixedLogs types.Logs
for _, l := range receipt.Logs {
if len(l.Topics) == 0 && len(l.Data) == 0 {
continue
Expand Down
22 changes: 11 additions & 11 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ var PrecompiledContractsBLS = map[libcommon.Address]PrecompiledContract{
}

var (
PrecompiledAddressesBerlin []libcommon.Address
PrecompiledAddressesIstanbul []libcommon.Address
PrecompiledAddressesByzantium []libcommon.Address
PrecompiledAddressesHomestead []libcommon.Address
PrecompiledAddressesEtrog []libcommon.Address
PrecompiledAddressesDragonfruit []libcommon.Address
PrecompiledAddressesForkId8 []libcommon.Address
PrecompiledAddressesBerlin []libcommon.Address
PrecompiledAddressesIstanbul []libcommon.Address
PrecompiledAddressesByzantium []libcommon.Address
PrecompiledAddressesHomestead []libcommon.Address
PrecompiledAddressesEtrog []libcommon.Address
PrecompiledAddressesDragonfruit []libcommon.Address
PrecompiledAddressesForkID88Elderberry []libcommon.Address
)

func init() {
Expand All @@ -139,16 +139,16 @@ func init() {
for k := range PrecompiledContractForkID7Etrog {
PrecompiledAddressesEtrog = append(PrecompiledAddressesEtrog, k)
}
for k := range PrecompiledContractsForkID8 {
PrecompiledAddressesForkId8 = append(PrecompiledAddressesForkId8, k)
for k := range PrecompiledContractsForkID88Elderberry {
PrecompiledAddressesForkID88Elderberry = append(PrecompiledAddressesForkID88Elderberry, k)
}
}

// ActivePrecompiles returns the precompiles enabled with the current configuration.
func ActivePrecompiles(rules *chain.Rules) []libcommon.Address {
switch {
case rules.IsForkID8:
return PrecompiledAddressesForkId8
case rules.IsForkID8Elderberry:
return PrecompiledAddressesForkID88Elderberry
case rules.IsForkID7Etrog:
return PrecompiledAddressesEtrog
case rules.IsForkID5Dragonfruit:
Expand Down
2 changes: 1 addition & 1 deletion core/vm/contracts_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var PrecompiledContractForkID7Etrog = map[libcommon.Address]PrecompiledContract{
}

// PrecompiledContractsForkID8 contains the default set of pre-compiled ForkID8.
var PrecompiledContractsForkID8 = map[libcommon.Address]PrecompiledContract{
var PrecompiledContractsForkID88Elderberry = map[libcommon.Address]PrecompiledContract{
libcommon.BytesToAddress([]byte{1}): &ecrecover_zkevm{enabled: true},
libcommon.BytesToAddress([]byte{2}): &sha256hash_zkevm{enabled: true},
libcommon.BytesToAddress([]byte{3}): &ripemd160hash_zkevm{enabled: false},
Expand Down
4 changes: 2 additions & 2 deletions core/vm/evm_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
func (evm *EVM) precompile(addr libcommon.Address) (PrecompiledContract, bool) {
var precompiles map[libcommon.Address]PrecompiledContract
switch {
case evm.chainRules.IsForkID8:
precompiles = PrecompiledContractsForkID8
case evm.chainRules.IsForkID8Elderberry:
precompiles = PrecompiledContractsForkID88Elderberry
case evm.chainRules.IsForkID7Etrog:
precompiles = PrecompiledContractForkID7Etrog
default:
Expand Down
2 changes: 1 addition & 1 deletion core/vm/interpreter_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NewZkConfig(config Config, counterCollector *CounterCollector) ZkConfig {
func getJumpTable(cr *chain.Rules) *JumpTable {
var jt *JumpTable
switch {
case cr.IsForkID5Dragonfruit, cr.IsForkID6IncaBerry, cr.IsForkID7Etrog, cr.IsForkID8:
case cr.IsForkID5Dragonfruit, cr.IsForkID6IncaBerry, cr.IsForkID7Etrog, cr.IsForkID8Elderberry:
jt = &forkID5DragonfruitInstructionSet
case cr.IsBerlin:
jt = &forkID4InstructionSet
Expand Down
2 changes: 1 addition & 1 deletion eth/stagedsync/stage_execute_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ func updateZkEVMBlockCfg(cfg *ExecuteBlockCfg, hermezDb *hermez_db.HermezDb, log
if err := update(chain.ForkID7Etrog, &cfg.chainConfig.ForkID7EtrogBlock); err != nil {
return err
}
if err := update(chain.ForkID8, &cfg.chainConfig.ForkID8Block); err != nil {
if err := update(chain.ForkID88Elderberry, &cfg.chainConfig.ForkID88ElderberryBlock); err != nil {
return err
}
return nil
Expand Down

0 comments on commit bccf530

Please sign in to comment.