Skip to content
Draft
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
3 changes: 3 additions & 0 deletions core/blockchain_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,9 @@ func (bc *BlockChainImpl) State() (*state.DB, error) {
}

func (bc *BlockChainImpl) StateAt(root common.Hash) (*state.DB, error) {
if bc.stateCache == nil {
return nil, fmt.Errorf("stateCache is nil, blockchain not properly initialized")
}
return state.New(root, bc.stateCache, bc.snaps)
}

Expand Down
3 changes: 2 additions & 1 deletion core/blockchain_leader_rotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func (bc *BlockChainImpl) buildLeaderRotationMeta(curHeader *block.Header) error
return nil
}
if curHeader.NumberU64() == 0 {
return errors.New("current header is genesis")
// Skip building leader rotation meta for genesis block
return nil
}
curPubKey, err := bc.getLeaderPubKeyFromCoinbase(curHeader)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion core/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ func getTestEnvironment(testBankKey ecdsa.PrivateKey) (*BlockChainImpl, *state.D

// fake blockchain
cacheConfig := &CacheConfig{SnapshotLimit: 0}
chain, _ := NewBlockChain(database, nil, nil, cacheConfig, gspec.Config, engine, vm.Config{})
chain, err := NewBlockChain(database, nil, nil, cacheConfig, gspec.Config, engine, vm.Config{})
if err != nil {
panic(fmt.Sprintf("failed to create blockchain: %v", err))
}
db, _ := chain.StateAt(genesis.Root())

// make a fake block header (use epoch 1 so that locked tokens can be tested)
Expand Down
5 changes: 4 additions & 1 deletion core/vm/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ func codeBitmap(code []byte) bitvec {
for pc := uint64(0); pc < uint64(len(code)); {
op := OpCode(code[pc])

if op >= PUSH1 && op <= PUSH32 {
if op == PUSH0 {
// PUSH0 doesn't read any bytes, just increment pc
pc++
} else if op >= PUSH1 && op <= PUSH32 {
numbits := op - PUSH1 + 1
pc++
for ; numbits >= 8; numbits -= 8 {
Expand Down
4 changes: 2 additions & 2 deletions core/vm/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type OpCode byte
// IsPush specifies if an opcode is a PUSH opcode.
func (op OpCode) IsPush() bool {
switch op {
case PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32:
case PUSH0, PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32:
return true
}
return false
Expand Down Expand Up @@ -474,9 +474,9 @@ var stringToOp = map[string]OpCode{
"MSIZE": MSIZE,
"GAS": GAS,
"JUMPDEST": JUMPDEST,
"PUSH0": PUSH0,
"TLOAD": TLOAD,
"TSTORE": TSTORE,
"PUSH0": PUSH0,
"PUSH1": PUSH1,
"PUSH2": PUSH2,
"PUSH3": PUSH3,
Expand Down
16 changes: 16 additions & 0 deletions internal/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ var (
HIP32Epoch: big.NewInt(2152), // 2024-10-31 13:02 UTC
IsOneSecondEpoch: EpochTBD,
EIP2537PrecompileEpoch: EpochTBD,
EIP3855Epoch: EpochTBD,
}

// TestnetChainConfig contains the chain parameters to run a node on the harmony test network.
Expand Down Expand Up @@ -133,6 +134,7 @@ var (
TestnetExternalEpoch: big.NewInt(3044),
IsOneSecondEpoch: EpochTBD,
EIP2537PrecompileEpoch: EpochTBD,
EIP3855Epoch: EpochTBD,
}
// PangaeaChainConfig contains the chain parameters for the Pangaea network.
// All features except for CrossLink are enabled at launch.
Expand Down Expand Up @@ -183,6 +185,7 @@ var (
TestnetExternalEpoch: EpochTBD,
IsOneSecondEpoch: EpochTBD,
EIP2537PrecompileEpoch: EpochTBD,
EIP3855Epoch: EpochTBD,
}

// PartnerChainConfig contains the chain parameters for the Partner network.
Expand Down Expand Up @@ -286,6 +289,7 @@ var (
TestnetExternalEpoch: EpochTBD,
IsOneSecondEpoch: EpochTBD,
EIP2537PrecompileEpoch: EpochTBD,
EIP3855Epoch: EpochTBD,
}

// LocalnetChainConfig contains the chain parameters to run for local development.
Expand Down Expand Up @@ -336,6 +340,7 @@ var (
TestnetExternalEpoch: EpochTBD,
IsOneSecondEpoch: big.NewInt(4),
EIP2537PrecompileEpoch: EpochTBD,
EIP3855Epoch: EpochTBD,
}

// AllProtocolChanges ...
Expand Down Expand Up @@ -390,6 +395,7 @@ var (
big.NewInt(0),
big.NewInt(0), // EIP2537PrecompileEpoch
big.NewInt(0), // 1153 transient storage
big.NewInt(0), // EIP3855Epoch
}

// TestChainConfig ...
Expand Down Expand Up @@ -444,6 +450,7 @@ var (
big.NewInt(0),
big.NewInt(0), // EIP2537PrecompileEpoch
big.NewInt(0), // 1153 transient storage
big.NewInt(0), // EIP3855Epoch
}

// TestRules ...
Expand Down Expand Up @@ -574,6 +581,9 @@ type ChainConfig struct {
// EIP2537PrecompileEpoch is the first epoch to support the EIP-2537 precompiles
EIP2537PrecompileEpoch *big.Int `json:"eip2537-precompile-epoch,omitempty"`

// EIP3855Epoch is the first epoch to support EIP-3855 (PUSH0 opcode)
EIP3855Epoch *big.Int `json:"eip3855-epoch,omitempty"`

// ChainIdFixEpoch is the first epoch to return ethereum compatible chain id by ChainID() op code
ChainIdFixEpoch *big.Int `json:"chain-id-fix-epoch,omitempty"`

Expand Down Expand Up @@ -877,6 +887,12 @@ func (c *ChainConfig) IsEIP1153TransientStorage(epoch *big.Int) bool {
return isForked(c.EIP1153TransientStorageEpoch, epoch)
}

// IsEIP3855 determines whether EIP-3855 (PUSH0 opcode)
// is available in the EVM
func (c *ChainConfig) IsEIP3855(epoch *big.Int) bool {
return isForked(c.EIP3855Epoch, epoch)
}

// IsChainIdFix returns whether epoch is either equal to the ChainId Fix fork epoch or greater.
func (c *ChainConfig) IsChainIdFix(epoch *big.Int) bool {
return isForked(c.ChainIdFixEpoch, epoch)
Expand Down
6 changes: 3 additions & 3 deletions node/harmony/worker/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ func TestNewWorker(t *testing.T) {
Config: chainConfig,
Factory: blockFactory,
Alloc: core.GenesisAlloc{testBankAddress: {Balance: testBankFunds}},
ShardID: 10,
ShardID: 0,
}
engine = chain2.NewEngine()
)

genesis := gspec.MustCommit(database)
_ = genesis
cacheConfig := &core.CacheConfig{SnapshotLimit: 0}
chain, err := core.NewBlockChain(database, nil, &core.BlockChainImpl{}, cacheConfig, gspec.Config, engine, vm.Config{})
chain, err := core.NewBlockChain(database, nil, nil, cacheConfig, gspec.Config, engine, vm.Config{})

if err != nil {
t.Error(err)
t.Fatalf("failed to create blockchain: %v", err)
}
// Create a new worker
worker := New(chain, nil)
Expand Down